I'm following this tutorial from Microsoft to use a Portable Class Library in a Windows Phone 8.1 WinRT Project. At the end they show an example in WPF.
It works well with WPF, you can use a class from the external library in the xaml for example to set the d:DataContext property of the window.
However with Windows Phone app, after adding the namespace alias in xaml, intellisense won't find the classes, and compiler insults me.
I found a workaround by creating dummy classes in the app project namespace, like this:
namespace App
{
public class dummyClass : externalLibrary.externalClass
{}
}
Using this, intellisense works.
Any idea how to fix this?
Related
i am having the following problem. i try to invoke platform specific code in the .NET MAUI from the microsoft tutorial.
https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/invoke-platform-code
The problem here is that it can be compiled and builded with Visual Studio, but with Rider from Jetbrains it cant be compiled.
i m getting the following error message:
DeviceOrientationService.cs(5, 38): [CS8795] Partial method 'DeviceOrientationService.GetOrientation()' must have an implementation part because it has accessibility modifiers.
Anyone got an idea what i am missing?
So the thing is you need to create an implementation for your abstract method on all platform classes for it to be able to build since you are targeting multiple platforms.
So just like you have an implementation in your Android and iOS platforms you need it on others as well.
There is another way as well which is you can create an abstract method with an implementation that already does something on other platforms so assume this method is only relevant on Android and iOS then you would do something like below in this class:
public partial class DeviceOrientationService
{
#if ANDROID || IOS
public partial DeviceOrientation GetOrientation();
#else
public partial DeviceOrientation GetOrientation()
{
return DeviceOrientation.Undefiend;
}
#endif
}
Also if you don't want to support Tizen, Windows or MacCatalyst you can just remove their references from the csproj file and then you can delete their platform folders and you won't need to do the above-mentioned things at all your app will only expect Android and iOS code for the above project.
I try to create a xamarin binding project for aar library. But if I add interface or class which extends SharedPreferences, it is not compiled. How to fix this?
See screenshot with logs below
I also created a project to demonstrate the issue.
https://github.com/3akat/SharedPrefsXamarinBindingIssueDemo
Is it possible to create a custom url based namespace in xamarin forms so that i can use xmlns:lib="http://schemas.officename.com/component/2015/xaml" instead of clr namespace like xmlns:lib="clr-namespace:Forms.Library.ontrols;assembly=Forms.Library"
like the examples here
http://www.codeproject.com/Articles/111911/A-Guide-to-Cleaner-XAML-with-Custom-Namespaces-and
http://www.kunal-chowdhury.com/2013/05/how-to-create-custom-xmlns-namespaces.html
i tried importing
using System.Windows.Markup;
in AssemblyInfo.cs, but it is not found also XmlnsDefinition and XmlnsPrefix are not there.
do i need to import any specific dll or those are not implemented in Xamarin Forms ?
I don't believe this approach is (currently) supported in the Xamarin.Forms implementation of XAML.
Why I do not have access to Attribute.IsDefined() in a portable class library? How could I use this method in PCL? In a class library the following code works perfect but in a pcl it says there is no method there.
if (Attribute.IsDefined(item, typeof(Title))) ...
Title is an attribute. Is it possible to solve this problem by adding a reference or something to the project?
I am trying to integrate the WeifenLuo.WinformsUI.Docking assembly into my application. To rule out external factors I created a new .Net 4 Winforms app and reference the DLL. Works fine.
I then created a .Net 4 Class Library and referenced the DLL. This this doesn't work and as soon as I try to use anything in that Docking namespace it won't compile.
To recap
C# Exe ---reference--> WeifenLuo.WinFormsUI.Docking.DockPanel.dll // OK
C# Class library ---reference--> WeifenLuo.WinFormsUI.Docking.DockPanel.dll // Not OK
I also have the WeifenLuo source and confirmed it's a class library referencing the same version of .Net. I tried adding a class library in their sample solution and referencing the WinForms project directly (not the result in assembly) and it still isn't linking properly.
Updating with Screenshot
You can't declare a private variable Inside a namespace.
Try the following code
namespace Test
{
public class Class1
{
private WeifenLuo.WinFormsUI.Docking.DockPanel dockPannel;
}
}
And if it still doesn't work, provide the error message.