Repository navigation
Description
What would you like to be added? 💡
Attached properties are DependencyProperty instances which use DependencyProperty.RegisterAttached(), such as:
namespace ShowMeTheXAML {
partial class XamlDisplayExtensions {
public static DependencyProperty HeaderProperty { get; } = DependencyProperty.RegisterAttached(
"Header",
typeof(string),
typeof(XamlDisplayExtensions),
new PropertyMetadata(default));
public static string GetHeader(XamlDisplay obj) => (string)obj.GetValue(HeaderProperty);
public static void SetHeader(XamlDisplay obj, string value) => obj.SetValue(HeaderProperty, value);
}
}The problem, from trimming or Native AOT perspectives, is that while HeaderProperty is preserved, there is no static connection between HeaderProperty, GetHeader, and SetHeader. Consequently, the GetHeader and SetHeader methods are likely to be removed.
The workaround is to use DynamicDependencyAttribute to connect HeaderProperty to it's dependencies:
namespace ShowMeTheXAML {
partial class XamlDisplayExtensions {
public static DependencyProperty HeaderProperty
{
[DynamicDependency(nameof(GetHeader))]
[DynamicDependency(nameof(SetHeader))]
get;
} = DependencyProperty.RegisterAttached(
"Header",
typeof(string),
typeof(XamlDisplayExtensions),
new PropertyMetadata(default));
public static string GetHeader(XamlDisplay obj) => (string)obj.GetValue(HeaderProperty);
public static void SetHeader(XamlDisplay obj, string value) => obj.SetValue(HeaderProperty, value);
}
}While this works, the problem is that this is tedious, and means that significant changes may be needed make apps work properly under Native AOT.
Proposal
The "100% correct" solution would be to scan IL looking for DependencyProperty.RegisterAttached() invocations, look at the first parameter, and automatically preserve methods with Get and Set prefixes on that value.
However, this approach is cumbersome. It's possible, but somewhat brittle.
As an easier -- if less correct -- solution: update the <BindableTypeLinkerGeneratorTask/> task (PR #22676) to check for static fields and properties of type DependencyProperty, remove the Property suffix from the name, and automatically preserve methods with Get and Set prefixes on the resulting name.
For example, given XamlDisplayExtensions.HeaderProperty:
- Remove the
Propertysuffix, resulting inHeader. - Check to see if
GetHeaderandSetHeaderexist in the same declaring type. - For the methods from (2) which exist, update
Uno.Bindable.Descriptor.xml-- or use a new file? -- to preserve those methods.
For example, Uno.Bindable.Descriptor.xml would contain the fragment:
<type fullname="ShowMeTheXAML.XamlDisplayExtensions" required="false">
<method name="GetHeader" />
<method name="SetHeader" />
</typeThis heuristic may be enough to avoid the need for scanning method body IL looking for DependencyProperty.RegisterAttached() invocations.
Why is this needed? 🤔
No response
Renderer 🎨
- Skia
- Native
For which platforms 📱💻🖥️
No response
Anything else we need to know? 💬
No response
Activity