ImageSource fallback only works when property is not registered.
I'd like my image to fall back to a static resource, if the string is null or empty in my noesis C++ project.
It does this in Blend.
But when running in Noesis in my game, I get nothing appearing when I've bound to a valid view model, with an empty image source.
I'm using strings for my image sources. So there must be a converter here, that's not failing when the source can't be resolved or is empty.
Is this intended behaviour?
Code: Select all
<Image x:Name="IconImage"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Grid.ColumnSpan="3"
Source="{Binding IconImageSource, FallbackValue={StaticResource FallbackOutfitImageSource}}"
Stretch="UniformToFill" />
But when running in Noesis in my game, I get nothing appearing when I've bound to a valid view model, with an empty image source.
I'm using strings for my image sources. So there must be a converter here, that's not failing when the source can't be resolved or is empty.
Is this intended behaviour?
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: ImageSource fallback only works when property is not registered.
The FallbackValue is used when the binding cannot be resolved (the property in the binding path can't be found for example).
If the binding was correctly evaluated but the return value was just null, then you should use the TargetNullValue property of the binding.
In the following xaml the second rectangle is filled with the Cyan color:
Is this what you're looking for?
If the binding was correctly evaluated but the return value was just null, then you should use the TargetNullValue property of the binding.
In the following xaml the second rectangle is filled with the Cyan color:
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid.Resources>
<SolidColorBrush x:Key="defBrush" Color="Magenta"/>
<SolidColorBrush x:Key="nilBrush" Color="Cyan"/>
</Grid.Resources>
<StackPanel>
<Rectangle x:Name="rect1" Width="200" Height="100" Fill="Red"/>
<Rectangle x:Name="rect2" Width="200" Height="100" Fill="{Binding Stroke, ElementName=rect1,
FallbackValue={StaticResource defBrush},
TargetNullValue={StaticResource nilBrush}}"/>
</StackPanel>
</Grid>
Re: ImageSource fallback only works when property is not registered.
Does TargetNullValue work correctly? Let's say I have a variable Name, my code returns an empty string in Name if it is not specified by the user, I bind <Run Text="{Binding Name, FallbackValue='Player Fall', TargetNullValue='Player Null' }" />. But I get Binding failed: Path=Name, Source=null(''), Target=Run(''), TargetProperty=Run.Text. The fallback value will be used. And accordingly empty text is returned. How it should work with a string value?
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: ImageSource fallback only works when property is not registered.
String properties are a bit different in Noesis compared to WPF because in C# strings are reference values that can be null, but not in C++.
So if the binding path is correct and the property returns an empty string then the binding will just use that value (no FallbackValue or TargetNullValue).
If you need your string properties to also support null values in C++ you should use a Nullable<String>. Anyway I'm seeing that even with that our behavior is different regarding bindings and TargetNullValue, could you please report this in our bugtracker?
So if the binding path is correct and the property returns an empty string then the binding will just use that value (no FallbackValue or TargetNullValue).
If you need your string properties to also support null values in C++ you should use a Nullable<String>. Anyway I'm seeing that even with that our behavior is different regarding bindings and TargetNullValue, could you please report this in our bugtracker?
Re: ImageSource fallback only works when property is not registered.
This is exactly what I was looking for!Is this what you're looking for?
I misunderstood the purpose of a fallback, and now it's working correctly. Thank you very much for clarifying!
Re: ImageSource fallback only works when property is not registered.
I reported this on the bug tracker. Please correct if something is wrong.String properties are a bit different in Noesis compared to WPF because in C# strings are reference values that can be null, but not in C++.
So if the binding path is correct and the property returns an empty string then the binding will just use that value (no FallbackValue or TargetNullValue).
If you need your string properties to also support null values in C++ you should use a Nullable<String>. Anyway I'm seeing that even with that our behavior is different regarding bindings and TargetNullValue, could you please report this in our bugtracker?
Link: https://www.noesisengine.com/bugs/view.php?id=3103
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: ImageSource fallback only works when property is not registered.
Thanks for the ticket!
Who is online
Users browsing this forum: Bing [Bot] and 2 guests