C
C#•3y ago
1FriendlyDoge

ā” Issue with NotifyCanExecuteChangedFor from MVVM CommunityTK

The problem occurs in my view model (Avalonia MVVM), I set a variable
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(PreCheckCommand))]
public string username;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(PreCheckCommand))]
public string username;
and try to run my function
[RelayCommand]
public void PreCheck() { ... }
[RelayCommand]
public void PreCheck() { ... }
whenever the text in to box is changed, it never executes though. Anyone has an idea what the issue is? This is how I use the binding in my xaml
<TextBox ... Text="{Binding Username, Mode=TwoWay}"></TextBox>
<TextBox ... Text="{Binding Username, Mode=TwoWay}"></TextBox>
27 Replies
Starlk
Starlk•3y ago
Did you set the data-context for the view?
1FriendlyDoge
1FriendlyDogeOP•3y ago
Other bindings work, so yeah
Starlk
Starlk•3y ago
what UI framework is this?
1FriendlyDoge
1FriendlyDogeOP•3y ago
Avalonia MVVM
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
twiner
twiner•3y ago
Notification is for properties not fields In wpf atleast
1FriendlyDoge
1FriendlyDogeOP•3y ago
Everything besides my function executing works, values update etc, so notification isnt the issue
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
And how do I get that?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
not there for me, do I have to put it into the constructor or something? Just typing it in the class doesnt work for me, although the object exists
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
I set the var to private, didnt change anything
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
partial
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
It inherits from ObservableObject
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
Oh, it needed partial void
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
That finally fixed it, wow, 2 hours wasted :( thank you a lot for helping me out!
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1FriendlyDoge
1FriendlyDogeOP•3y ago
Yeah, I would have never guessed this, pretty weird way to go about this in my opinion...
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
333fred
333fred•3y ago
/cc @Sergio
Sergio
Sergio•3y ago
You're confusing things NotifyCanExecuteChangedFor doesn't invoke your command It just causes the command to signal its CanExecuteChanged event šŸ™‚ This was in reply to this šŸ˜„ If you want to run code whenever that changes, just do:
partial void OnUsernameChanged(string value)
{
// TODO: do stuff here
}
partial void OnUsernameChanged(string value)
{
// TODO: do stuff here
}
šŸ™‚
Accord
Accord•3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?