C
C#2y ago
Elio

Command WPF with viewmodel

Hello, i'm looking for some help : I'm currently developing an app with wpf using the mvvm model and i'm struggling with the command of my button, i do not understand why they aren't triggered when i click on it, the break point is not hit but the viewmodel assign to my view seem to be correctly loaded. I've already tested the command which isn't the problem but it seem to come from the page cause the command trigger work on the other page but not on this one. the second image show the click event i've setup just to test if there is a datacontext and if command work well and it seem to work cause the command is correctly triggered when i used the click event but not when i use the button with the command in the first image. do you have any idea what can be the cause of this problem ? (i suppose it's something related to my navigation service or my host declaration with the Singleton etc. but not sure) Or how am i supposed to debug this ?
5 Replies
Djostit
Djostit2y ago
I advise you to use DevExpress. As I understand it, you are violating the MVVM principles. When using DevExpress you need to inherit BindableBase in your ViewModel
public DelegateCommand TestCommand => new(() =>
{
Debug.WriteLine("It's working");
});
public DelegateCommand TestCommand => new(() =>
{
Debug.WriteLine("It's working");
});
command example In the xaml you need to specify DataContext to be able to bind.
<Page.DataContext>
<local:TestVM />
</Page.DataContext>
<Page.DataContext>
<local:TestVM />
</Page.DataContext>
Elio
ElioOP2y ago
personnaly i've bind the vm with this :
<DataTemplate DataType="{x:Type vm:MaterialViewModel}">
<views:MaterialView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:MaterialViewModel}">
<views:MaterialView />
</DataTemplate>
Djostit
Djostit2y ago
In the screenshot I see that he does not see the command
Elio
ElioOP2y ago
i've the same thing in this page too but the command work well
Elio
ElioOP2y ago
ok i found my problem i guess i forgot to add { get; } at the end of my command declaration ... in my viewmodel public ICommand NavigateMaterialCommand { get; }
Want results from more Discord servers?
Add your server