General guidance for making UWP-only code Uno compatible
This article explains adjustments that may need to be made to UWP-only code for it to run on Uno Platform, be it in an application or a class library.
Add 'partial' to some class definitions
Certain class definitions will need to have the
partial keyword added. This is because Uno generates additional code at compile-time to support them properly.
You'll need to do this for:
- types that inherit from
FrameworkElement, directly or indirectly
- types that inherit directly from
Apart from adding
partial, you don't need to worry about the generated code. You may however get misleading errors from Intellisense until the first time you try to compile the project, because the generated partial classes haven't been added yet.
Avoid nested classes that inherit from FrameworkElement
Classes that inherit from
FrameworkElement directly or indirectly can't be nested inside another class; it's been observed to cause problems on Xamarin.iOS. If you have any nested
FrameworkElement-derived classes, you'll need to refactor them to be top-level classes.
Disambiguate naming collisions with native properties
This is relevant if you're targeting Android, iOS, and/or macOS, where Uno views (hence,
FrameworkElement) inherit from the native view type. In some cases you may find that a reference to a type from the UWP framework is confused with a native property. The fix in this case is generally to disambiguate by supplying the full namespace of the type.
Some common cases:
- on iOS, inside a control definition, references to
Window.Currentwill be confused with the
UIView.Windowproperty. The fix is to fully qualify this as
- on Android, inside a control definition, references to the
TextAlignmentenum will be confused with the
View.TextAlignmentproperty. The fix, again, is to fully qualify the reference as
What do I do if I have a nested namespace with
Windows in it?
If, for example, your control is defined in the
CoolControls namespace, and you've also defined a
CoolControls.Windows namespace, then the above will give a compilation error. You'll need to use the
global keyword, eg
Adjust for unsupported runtime features
Not all .NET runtime features are supported on every platform. See here for more details.