Cannot set Dependency Property of the FontWeight? (Nullable<FontWeight>) type in XAML
See original GitHub issueDescribe the bug
public class MyControl : Control {
public static readonly DependencyProperty NullableStructProperty = DependencyProperty.Register("NullableStruct", typeof(FontWeight?), typeof(MyControl), new PropertyMetadata(null));
public FontWeight? NullableStruct { get { return (FontWeight?)GetValue(NullableStructProperty); } set { SetValue(NullableStructProperty, value); } }
}
<local:MyControl x:Name="c3" NullableStruct="Bold"/>
Result: ‘XAML parsing failed.’ 'Failed to create a ‘Windows.Foundation.IReference`1<Windows.UI.Text.FontWeight>’ from the text ‘Bold’.
Reproduced in any version, including 1.0.0-preview2
Steps to reproduce the bug
Run sample App1.zip
Expected behavior
No response
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 0.8: 0.8.0 (If you’re seeing your issue in older previews of WinUI 3, please try this release)
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
May 2021 Update (19043)
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Dependency Property - Unable to Set Value From XAML
When I add that code it says that the string PassColor is invalid. Without the string there at all, the code compiles and...
Read more >WPF set from DependencyProperty not set a value if DP is ...
Meaning, no, you cannot ensure the set accessor is called. It never will be. This is not a true. Of course, never will...
Read more >TextElement.FontWeight Property
Gets or sets the top-level font weight for the content of the element. ... This dependency property also has an attached property usage....
Read more >Can't Set WPF Custom Control Dependency Property from ...
Hello,. I've created a "nav button" custom control, with the goal of simply passing it an icon path, and then the text that...
Read more >Dependency Properties | WPF Fundamentals
WPF introduces a type of property called a dependency property that is used throughout the platform to enable styling, automatic data ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It doesn’t work for non-dependency (simple) properties too:
This looks like a bug where the framework doesn’t support unboxing
FontWeight
from a string (for MSFT employees, this code needs avalueString
case to create aFontWeight
from a string).