Replies: 6 comments 2 replies
-
Hi there, I think it will be simpler if you provide some small reproduction repo or at least some code. It might be something small but it's hard to guess like that 😉 |
Beta Was this translation helpful? Give feedback.
-
@OvrBtn Yeah, I can definitely try! So this is something like my MainPage.xaml, I have a view model for the page, and a custom control, a property of which is bound to some property on the view model.
This is the view model (MyPageVM.cs) with that property (I'm using the communitytoolkit.mvvm helpers here, not sure if that is part of the issue):
Then I have my custom control defined something like this: MyControl.xaml
MyControl.xaml.cs:
|
Beta Was this translation helpful? Give feedback.
-
I took a quick look and I'm seeing 2 issues:
it shoudl be
The public property being "public string FromViewModel {get;set;}" is automatically generated by CommunityToolkit with all the logic to invoke OnPropertyChanged when needed, that's the whole point of using this attribute. IntelliSense should tell you that what you've made is wrong. Also remember that when using [ObservableProperty] you class has to be partial.
it should be
Checkout docs |
Beta Was this translation helpful? Give feedback.
-
@OvrBtn thanks for the detailed reply. I was rushing some stuff on friday, so I'm sorry the example wasn't totally complete. The edits you suggested I actually already had in my code (which I should have referenced rather than trying to do from memory). The bindable properties have backing fields, and the ObservableProperty fields are private and lowerCamelCase already. I also should add that the type of the property is a custom object that I have defined, so it is a non-trivial type. I don't know if that would make a difference either. |
Beta Was this translation helpful? Give feedback.
-
That's okay. In terms of the non trivial type, it really depends on what you do. For example let's imagine that FromViewModel is not type of string but some more complex class so if you do |
Beta Was this translation helpful? Give feedback.
-
GAH. This is so frustrating. I've somehow tied myself into a knot, I'm sure what I am doing wrong is super simple. Crucial detail I'm finding: The property is updated in my Model, not the view model. I believe my view model actually holds a reference to the data in the model. When that data is changed (in the model) the UI doesn't reflect that change. That is where I get stuck. In the model we are updating some sub-field of the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey y'all. I know this is probably the thousandth time someone has asked a question like this, but I have done a lot of digging and cannot seem to find a solution to what is apparently a problem that is unique to me (please prove me wrong, this is driving me nuts).
I have a custom control (XAML w/ C# code behind). There is a bindable property on that control. The UI for the control references values stored in that property for display through data binding.
That bindable property can be bound to by the page that consumes the control, such that the view model for the page can be used as the source for the object that goes into that binding.
However, when I update the property on the view model with some new data, the UI doesn't reflect the change. I have tried every binding mode and source and reference known to man, and cannot seem to get it working. If this isn't enough detail, please let me know and I'll provide a MRE (minimum repro example).
Beta Was this translation helpful? Give feedback.
All reactions