-
Notifications
You must be signed in to change notification settings - Fork 803
Description
Describe the bug
When binding to a function, where part of the path is null and supplying a parameter that is related to a UI element, a NullReferenceException is thrown.
It does not respect the FallbackValue.
It only happens in Debug mode, and not in Release mode, but it makes it difficult to actually use this feature.
Having a static parameter value for instance works (returning null, or the FallbackValue if configured).
So, this line works:
<TextBlock Text="{x:Bind NullInstance.MyFunction(20), FallbackValue='null'}"/>
but this does not:
<TextBlock Text="{x:Bind NullInstance.MyFunction(RootElement.ActualWidth), FallbackValue='null'}"/>
Steps to reproduce the bug
Create a WinUI 3 project, add a class with a function:
public class TestClass
{
public string MyFunction(double width)
{
return width.ToString();
}
}
In the code behind for the main window, add:
public TestClass Instance { get; } = new TestClass();
public TestClass NullInstance { get; } = null;
and in the Xaml for the main window, add:
<Grid x:Name="RootElement">
<StackPanel>
<TextBlock Text="{x:Bind NullInstance.MyFunction(20), FallbackValue='null'}"/>
<TextBlock Text="{x:Bind Instance.MyFunction(RootElement.ActualWidth), FallbackValue='null'}"/>
</StackPanel>
</Grid>
This example will work, but changing the Xaml to bind to NullInstance throws.
Expected behavior
Expected the FallbackValue to be returned, or null if none defined.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.6: 1.6.250228001
Windows version
Windows 11 (24H2): Build 26100
Additional context
This is reproducible in App SDK 1.7 as well