You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm extending NavigationView with a SettingsItemInfoBadge property (as WinUI does not natively provide this). Trying to use it in XAML causes a XamlParseException with the message "The text associated with this error code could not be found." and "Failed to assign to property 'Example.Utility.Extensions.NavigationViewExtensions.SettingsItemInfoBadge'."
Steps to reproduce the bug
NavigationViewExtensions.cs:
using Microsoft.UI.Xaml;using Microsoft.UI.Xaml.Controls;namespace Example.Utility.Extensions;internalstaticclassNavigationViewExtensions{publicstaticreadonlyDependencyPropertySettingsItemInfoBadgeProperty= DependencyProperty.RegisterAttached("SettingsItemInfoBadge",typeof(InfoBadge),typeof(NavigationViewExtensions),new PropertyMetadata(new InfoBadge(), OnSettingsItemInfoBadgeChanged));publicstaticvoidSetSettingsItemInfoBadge(UIElementelement,InfoBadgevalue){
element.SetValue(SettingsItemInfoBadgeProperty, value);}publicstatic InfoBadge GetSettingsItemInfoBadge(UIElementelement){return(InfoBadge)element.GetValue(SettingsItemInfoBadgeProperty);}privatestaticvoidOnSettingsItemInfoBadgeChanged(DependencyObjectsender,DependencyPropertyChangedEventArgsargs){if(sender is not NavigationView navigationView){return;}if(navigationView.SettingsItem is NavigationViewItem settingsItem){
settingsItem.InfoBadge =(InfoBadge)args.NewValue;}}}
Note: using SetSettingsItemInfoBadge() in the code-behind works perfectly fine. OnSettingsItemInfoBadgeChanged() can be empty and still yield the error. In XAML, if <extensions:NavigationViewExtensions.SettingsItemInfoBadge> is empty (i.e. no <InfoBadge> is provided), no error occurs.
Expected behavior
No error should occur or the error provided should be more descriptive.
NuGet package version
WinUI 3 - Windows App SDK 1.5.3: 1.5.240428000
Windows version
Windows 10 (22H2): Build 19045.4291
The text was updated successfully, but these errors were encountered:
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Poyo-SSB
changed the title
Using a custom DependencyProperty extension causes XamlParseException on property assignment
Using a custom DependencyProperty extension in XAML causes XamlParseException on property assignment
May 27, 2024
Describe the bug
I'm extending NavigationView with a SettingsItemInfoBadge property (as WinUI does not natively provide this). Trying to use it in XAML causes a
XamlParseException
with the message "The text associated with this error code could not be found." and "Failed to assign to property 'Example.Utility.Extensions.NavigationViewExtensions.SettingsItemInfoBadge'."Steps to reproduce the bug
NavigationViewExtensions.cs
:MainWindow.xaml
:Note: using
SetSettingsItemInfoBadge()
in the code-behind works perfectly fine.OnSettingsItemInfoBadgeChanged()
can be empty and still yield the error. In XAML, if<extensions:NavigationViewExtensions.SettingsItemInfoBadge>
is empty (i.e. no<InfoBadge>
is provided), no error occurs.Expected behavior
No error should occur or the error provided should be more descriptive.
NuGet package version
WinUI 3 - Windows App SDK 1.5.3: 1.5.240428000
Windows version
Windows 10 (22H2): Build 19045.4291
The text was updated successfully, but these errors were encountered: