✅ How does the button know what to do?
Hey, new to C# and wrapping my head around following MVVM. Can someone help me understand how the button knows what to do here? When adding a new button or data binding, they all trigger each other (if that makes sense...). Will any button trigger all data bindings unless otherwise set with like a command relay or something?
XAML:
Code Behind:
View Model:
25 Replies
In this case nothing will display in data bindings because your ViewModel doesn’t implement the ‘INotifyPropertyChanged’ interface
wdym? the button doesnt do anything
But it is working :\
also
I am using a base for my view mode that is using INotify but it's not being inherited anywhere
wdym by working?
If I type into the text box and press the button, the text is displayed in the textblock
And I just checked, I haven't even changed my ViewModel bases namespace from another project I copied it from.
huh
so are you raising a change notification anywhere?
I'm going to say no but not 100% sure. The only place I have an event is in the base
can you show you entire viewmodel?
This is the base if it matters, but yeah NAmespace is wrong and I'm not inheriting it as far as I know.
your viewmodel doesnt inherit from your base?
also the underscores in names are very unconventional
Yeah, it's muscel memory still haha.
oh yeah wtf
any random button makes the binding update somehow
I tried putting it into a different grid as well (Within the main one, whatever it's called) and same thing.
That is about all I tried if I'm being honest though haha.
ohh i see whats happening here
its weird wpf defaults
the default binding mode for text boxes in wpf is two way, and the default
UpdateSourceTrigger
is LostFocus
so when you type in the textbox, it sets the property, and when you press the button, the focus trigger is triggered and it reads the new propertyOhh, so whenever I click set, I'm jsut losing focus.
Ahhh, thanks so much mate!
yeah, whenever the textbox loses focus
I would never have figured that out haha.
yeah thats why i like to explicitly set these things, not leave the defaults
Yeah, I'll keep defaults in mind from now on for sure haha.
Thanks again!
no worries
also keep in mind that the defaults may vary between controls
The default value varies for each dependency property. In general, user-editable control properties, such as those of text boxes and check boxes, default to two-way bindings, whereas most other properties default to one-way bindings.https://learn.microsoft.com/en-us/dotnet/api/system.windows.data.bindingmode?view=windowsdesktop-8.0#system-windows-data-bindingmode-default $close @intee_
If you have no further questions, please use /close to mark the forum thread as answered
Legend man. thanks for all the help! It's making so much more sense now hahah..