I have a Visual Studio 2019 UWP project with a XAML page using dependency properties for binding values. It's all working fine in debug mode but not in release. What's wrong with the way I am binding that VS relase doesn't like?
The sample code below shows a Windows.UI.Xaml.Controls.FontIcon with a binding to MyDependencyClass DependencyObject class.
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="{Binding ElementName=MyPageUI, Path=(local:myDependencyClass.myGlyph)}" />
The error is Windows.UI.Xaml.Markup.XamlParseException: 'XAML parsing failed.', and it is due to this binding in the FontIcon element. It does not matter the type of control, same error.
{Binding ElementName=MyPageUI, Path=(local:myDependencyClass.myGlyph)}
public abstract class MyDependencyClass : DependencyObject
{
public static readonly DependencyProperty MyGlyphProperty;
public static void SetMyGlyph(DependencyObject DepObject, string value)
{
DepObject.SetValue(MyGlyphProperty, value);
}
public static string GetMyGlyph(DependencyObject DepObject)
{
return (string)DepObject.GetValue(MyGlyphProperty);
}
static MyDependencyClass()
{
PropertyMetadata MyPropertyMetadata = new PropertyMetadata("\xE72E");
MyGlyphProperty = DependencyProperty.RegisterAttached("MyGlyph",
typeof(string),
typeof(MyDependencyClass),
MyPropertyMetadata);
}
It's all working fine in debug mode but not in release.
I could reproduce your problem, and xaml binding code make sense, please feel free post your problem with windows feed back hub or post in WinUI issue box. And currently we have a workaround that replace Binding
with x:Bind
, and use static property to replace Attached property.
Xaml
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="{x:Bind local:TestClass.Glyph}" />
Code
public static class TestClass
{
public static string Glyph
{
get
{
return "\xE72E";
}
}
}