Open takla21 opened 1 year ago
When trying to bind to the datacontext with RelatedSource, it will display the fallback value.
RelatedSource
<TextBlock Text="{Binding Content, RelativeSource={RelativeSource Mode=TemplatedParent}, FallbackValue='RelativeSource binding failed'}" />
In UWP, we can use RelativeSource inside our bindings to get to the DataContext. It's quite useful especially when we need to use a converter.
RelativeSource
<ListView ItemsSource="{Binding}"> <ListView.ItemTemplate> <DataTemplate> <StackPanel x:Name="Parent" DataContext="{Binding}"> <TextBlock Text="{Binding}" /> <TextBlock Text="{Binding Content, RelativeSource={RelativeSource Mode=TemplatedParent}, FallbackValue='RelativeSource binding failed'}" /> <TextBlock Text="{Binding ElementName=Parent, Path=DataContext, FallbackValue='Workaround binding failed'}" />
Store the datacontext in a parent xaml element and bind from it.
<StackPanel x:Name="Parent" Background="Red" DataContext="{Binding}"> <!-- Workaround text --> <TextBlock Text="{Binding ElementName=Parent, Path=DataContext, FallbackValue='Workaround binding failed'}" /> </StackPanel>
Yes
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
4.9.0-dev.439
Android, iOS
Visual Studio 2022
17.4.3
No response
This may be fixed now with #17645
Current behavior
When trying to bind to the datacontext with
RelatedSource
, it will display the fallback value.Expected behavior
In UWP, we can use
RelativeSource
inside our bindings to get to the DataContext. It's quite useful especially when we need to use a converter.How to reproduce it (as minimally and precisely as possible)
Workaround
Store the datacontext in a parent xaml element and bind from it.
Works on UWP/WinUI
Yes
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
4.9.0-dev.439
Affected platforms
Android, iOS
IDE
Visual Studio 2022
IDE version
17.4.3
Relevant plugins
No response
Anything else we need to know?
No response