WindowsCommunityToolkit
WindowsCommunityToolkit copied to clipboard
[ObservableProperty] on a model don't update the UI
Describe the bug
Hi! I have a weird problem with the ObservableProperty. When I create a property in the ViewModel, if I create a string, int, bool etc...or an ObservableCollection<MyModel> the Ui update without any problem. When I create a properties of the Model itself it's not working.
For example
//I Try with the INotifyPropertyChanged on the top of each ViewModel or make the ViewModelBase an ObservableObject, that change nothing.
[INotifyPropertyChanged]
public class MainViewModel : ViewModelBase
{
public MainViewModel(){}
public void Method()
{
// If I bind the Text to this it's working
Name = GetName();
// This is not working
Form.Name = GetName();
}
[ObservableProperty] private string Name;
[ObservableProperty] private FormModel Form;
}
public class FormModel
{
public string Name {get;set;}
}
I Change of course the DataContext of the StackPanel and even the intellisence can see the property. I try with one way, two way UpdateSourceTrigger=PropertyChanged. Nothing work.
Regression
IDK
Reproducible in sample app?
- [ ] This bug can be reproduced in the sample app.
Steps to reproduce
1.Create a model
2.In the viewModel, create a [ObservableProperty] of the model
3.Create a textBox in the view
4.Update the Name property.
Expected behavior
Expect the UI to get the update
Screenshots
No response
Windows Build Number
- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)
Other Windows Build number
No response
App minimum and target SDK version
- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Other (specify)
Other SDK version
No response
Visual Studio Version
No response
Visual Studio Build Number
No response
Device form factor
No response
Nuget packages
No response
Additional context
No response
Help us help you
Yes, but only if others can assist.
Hello meilleur102, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌
Wrong repo:
https://github.com/CommunityToolkit/dotnet
MB sorry