WPF, C#, MVVM Notify ViewModel dynamically in changes from Model
Clash Royale CLAN TAG#URR8PPP
WPF, C#, MVVM Notify ViewModel dynamically in changes from Model
I have ViewModel that makes some functions. Funcs are initiate by button, i have command on button click.
ViewModel.cs
ViewModel.cs
class WindowViewModel : INotifyPropertyChanged
{
public WindowViewModel()
canExecute = true;
public ICommand ApplyKMMCommand //command for button click
get
return applyKMMCommand ?? (applyKMMCommand = new Commands.CommandHandler(() =>
ApplyKMMToNewImage(), canExecute));
private bool canExecute;
private ICommand applyKMMCommand;
public void ApplyKMMToNewImage()
ApplyKMM.Init(); //algorithm name
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public BitmapImage DisplayedImage //displaying image that i work with
get return Bitmaps.Filepath;
set Bitmaps.Filepath = value; NotifyPropertyChanged(nameof(DisplayedImage));
Now, my ApplyKMM.Init()
ApplyKMM.Init()
class ApplyKMM
public static void Init()
Bitmaps.Filepath = //do some thing with it...
And my Models.Bitmaps.cs
Models.Bitmaps.cs
static public BitmapImage Filepath
get return filepath;
set filepath = value;
static private BitmapImage filepath get; set;
The problem is, when i make ApplyKMM.Init
the Image
control that is binded to View not change their value.
ApplyKMM.Init
Image
Without ApplyKMM
i can do in ViewModel that thing:
ApplyKMM
DisplayedImage = //do things with bitmap...
And then, Image
that is presented in View change (after making things with that image).
Image
Can you tell me, how to notify ViewModel, that somewhere in code filepath
from Models changed?
filepath
EDIT:
Binding in View
Looks like standard binding:
View
<Image Source="Binding DisplayedImage"/>
Button click works too, i have problem only with communication between Models->ApplyKMM->ViewModel
Models->ApplyKMM->ViewModel
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.