Jarryd
Topic Author
Posts: 14
Joined: 05 Sep 2023, 07:25

ImageSource fallback only works when property is not registered.

13 Feb 2024, 01:11

I'd like my image to fall back to a static resource, if the string is null or empty in my noesis C++ project.
             <Image x:Name="IconImage"
                    Grid.Row="0"
                    Grid.RowSpan="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="3"
                    Source="{Binding IconImageSource, FallbackValue={StaticResource FallbackOutfitImageSource}}"
                    Stretch="UniformToFill" />
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?
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: ImageSource fallback only works when property is not registered.

15 Feb 2024, 19:21

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:
<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>
Is this what you're looking for?
 
Demond
Posts: 11
Joined: 06 Feb 2023, 23:32

Re: ImageSource fallback only works when property is not registered.

17 Feb 2024, 16:45

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?
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: ImageSource fallback only works when property is not registered.

19 Feb 2024, 11:54

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?
 
Jarryd
Topic Author
Posts: 14
Joined: 05 Sep 2023, 07:25

Re: ImageSource fallback only works when property is not registered.

20 Feb 2024, 06:19

Is this what you're looking for?
This is exactly what I was looking for!
I misunderstood the purpose of a fallback, and now it's working correctly. Thank you very much for clarifying!
 
Demond
Posts: 11
Joined: 06 Feb 2023, 23:32

Re: ImageSource fallback only works when property is not registered.

20 Feb 2024, 17:40

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?
I reported this on the bug tracker. Please correct if something is wrong.

Link: https://www.noesisengine.com/bugs/view.php?id=3103
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: ImageSource fallback only works when property is not registered.

22 Feb 2024, 10:54

Thanks for the ticket!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], mariehartley and 1 guest