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
Elio2y 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
Elio2y ago
i've the same thing in this page too but the command work well
Elio
Elio2y 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
More Posts
✅ How do I make an exponent in winforms?I'm trying to make a random math test simulator for finding the roots of a quadratic equation. I'm n❔ Own map with the possibility of embedding points.Hi, I'm looking for a library that in blazor will allow me to create my own map (with my own backgro❔ .NET 6.0 - Nullable Strings with Dapper Model ClassesHey everyone. I have a .NET 6.0 project that uses Dapper to communicate to a database and I have a c❔ Merging two projects togetherGotta merge two projects together but the issue is some of my partners code is running errors when i❔ ✅ Deserializing a JSON array that contains a derived type AND a base type with JSON.NET?I have three classes: ``` ScratchTarget ├─ ScratchScene └─ ScratchSprite ``` `ScratchTarget`❔ Question How can I get the name of the application the user is currently focused on?So I have a .NET 7.0 app, and I want to see if the app the user is focused on is firefox/chrome, and❔ Assigning variables in switch caseWhy am I getting this error? I want to assign the value of `totalBeat` depending on the sign of `meHow to generate a category tree```cs public class Category { public int Id { get; set; } public Thread Thread { get; set; ❔ New .NET Template fails GitHub action buildhttps://github.com/dzenis-zigo/Frizerski-Salon-ML I don’t think I made one change to the ASP.NET we✅ Cannot convert from string[] to 'char' [SOLVED]Hi, I'm getting this error that I am converting from string[] to char. The data type for the field