0

I want to change the .ico depending on which Checkbox is checked:

        <MenuItem Header="_Online" Command="{Binding SetStatusOnlineCommand}"  />
        <MenuItem Header="_Away" Command="{Binding SetStatusAwayCommand}" />
        <MenuItem Header="_Offline" Command="{Binding SetStatusOfflineCommand}" />

Since I am using MVVM Light and it's SimpleIoC I don't know how to achieve this.

My ViewModel doesn't know the Window it's representing, and thus I can't change the Icon of the Window. My Window get's it DataContext inside XAML via the localter:

<DockPanel x:Name="MainPanel"  DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">

I wanted to create a PropertyChangeEvent inside my ViewModel. The Window registers to this event, but since I am instanciating via the Locator inside my XAML, I don't have access to it from my Window, or am I wrong?!

I could use OnChange-Events ... but then I will break the MVVM pattern. Does anyone have a nice idea ho to achieve this?!

DoubleVoid
  • 777
  • 1
  • 16
  • 46
  • Looks like a perfect use case for publish-subscriber pattern: Your Command(s) send a Message; your Windows subscribes to this messages and acts accordingly. – Filburt Nov 02 '15 at 14:54
  • I'd bind the window's `Icon` property to a `Status` property in the view-model, with a converter or data-trigger to select the appropriate icon based on the value of that property. – Pieter Witvoet Nov 02 '15 at 15:51

1 Answers1

2

You can pass the window as a command parameter:

<MenuItem Header="_Online" Command="{Binding SetStatusOnlineCommand}"
CommandParameter="{Binding ElementName=YourWindowName}" />

Explained here: https://stackoverflow.com/a/16195267/5147720

Community
  • 1
  • 1
Jose
  • 1,857
  • 1
  • 16
  • 34