maui
maui copied to clipboard
DataTrigger.Value Does Not Respond to Data Binding
Description
Simple repro. With or without MVVM and Community Toolkit helpers, the issue occurs for me on Android and Windows. Maybe DataTrigger.Value isn't meant to use data bindings, but that is not in the documentation if so, and it seems logically it should.
When using a DataTrigger, when DataBinding the DataTrigger.Value to a value in the ViewModel or code behind, the trigger does not work:
<VerticalStackLayout Grid.Row="1" Grid.Column="1" >
<Label Text="{Binding Int1}"
FontSize="20"
Padding="7" >
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Int1}"
Value="{Binding Int2}">
<Setter Property="BackgroundColor"
Value="DarkSeaGreen"/>
</DataTrigger>
</Label.Triggers>
</Label>
<Label Text="{Binding Int2}"
FontSize="20"
Padding="7" >
</Label>
</VerticalStackLayout>
If DataTrigger.Value is explicitly set to a value such as "2", it works:
<VerticalStackLayout Grid.Row="3" Grid.Column="1" >
<Label Text="{Binding Int1}"
FontSize="20"
Padding="7" >
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Int1}"
Value="2">
<Setter Property="BackgroundColor"
Value="DarkSeaGreen"/>
</DataTrigger>
</Label.Triggers>
</Label>
<Label Text="{Binding Int2}"
FontSize="20"
Padding="7" >
</Label>
</VerticalStackLayout>
For the DataTrigger in this example, if Int1 = Int2, I expect the label background to turn DarkSeaGreen, regardless if DataTrigger.Value is explicitly typed, or generated via data binding.
Int1 and Int2 are initialized in the ViewModel (using Community Toolkits mentioned above):
[ObservableProperty]
int int1 = 0;
[ObservableProperty]
int int2 = 2;
Steps to Reproduce
Create DataTrigger where DataTrigger.Value is a databinding.
When DataTrigger.Binding = DataTrigger.Value, the trigger should trigger.
Link to public reproduction project repository
https://github.com/Quaybe/TriggerTestMaui
Version with bug
8.0 (Current)
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows, iOS
Affected platform versions
Windows 10.0.19041.0, Android 10+, iOS 17
Did you find any workaround?
No response
Relevant log output
No response