CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

DataTrigger does not respond to change in bound property #752

Closed rwhitecpf closed 1 year ago

rwhitecpf commented 1 year ago

Describe the bug

UPDATE: I found that the trigger doesn't respond if it is bound to a built-in type. If you wrap the property in a class that inherits from ObservableClass, then the screen updates when the value changes. This applies to strings as well. I bound a TextBlock to a string and changed it, but the change didn't happen on the screen. When I wrapped the string in a class, the any changes to the string immediately seen on the screen.

I hope this helps in diagnosing.

ORIGINAL POST I am writing a user control for our legacy application. I like put a blue border around the data and change it to red to indicate that they changed something. The XAML is as follows:

`<Border Grid.Row="1" Grid.Column="0" Margin="5,5" BorderThickness="2">

` and the bound property is pretty basic ` private bool _destinationsChanged; /// /// Sets and gets the DestinationsChanged property. /// Changes to that property's value raise the PropertyChanged event. /// public bool DestinationsChanged { get => _destinationsChanged; set => SetProperty(ref _destinationsChanged, value); } ` When the property changes, the color doesn't automatically change. However, it you leave the control and come back to it, the color now displays as red. I am using .Net Framework 4.8 on Windows. I saw what looks like the same issue under MAUI [https://github.com/dotnet/maui/issues/12305](url) ### Regression _No response_ ### Steps to reproduce ```text Create the DataTrigger under the Style Trigger for the border that changes the border color to red when DestinationsChanged is true. Change the value of DestinationsChanged to true. ``` ### Expected behavior The border color should change to red. ### Screenshots _No response_ ### IDE and version VS 2022 ### IDE version 17.6.5 ### Nuget packages - [ ] CommunityToolkit.Common - [ ] CommunityToolkit.Diagnostics - [ ] CommunityToolkit.HighPerformance - [X] CommunityToolkit.Mvvm (aka MVVM Toolkit) ### Nuget package version(s) 8.2.1 ### Additional context _No response_ ### Help us help you No, just wanted to report this
rwhitecpf commented 1 year ago

I was able to get this to work by raising the property changed event.