I would like to Minimize my application by clicking on a UserControl button using MVVM.
Here is my ViewModel class:
public class HeaderViewModel : ViewModelBase, IHeaderViewModel
{
public DelegateCommand MinimizeWindowCommand { get; set; }
public HeaderViewModel(IHeaderView view) : base(view)
{
MinimizeWindowCommand = new DelegateCommand(OnMinimizeWindow);
}
private void OnMinimizeWindow()
{
/*
* This is where I would like to minimize my Application
* Something like MainWindow
*/
}
}
When I click on my UserControl button, the MinimizeWindowCommand is called. In the OnMinimize() method, I wish to set the MainWindow visibility to Hidden.
By the way, I am using Prism and the UserControl is directly injected in the MainWindow as follow :
<Window
xmlns:prism="http://prismlibrary.com/"
[...]
Title="Shell"
x:Name="Shell">
<ScrollViewer>
<StackPanel>
<ContentControl prism:RegionManager.RegionName="{x:Static infra:RegionNames.HeaderRegion}" />
</StackPanel>
</ScrollViewer>
</Window>
Thank you ! Chcoum
HeaderViewModel
is theDataContext
of, right? Or what's the relationship between the view model and the window that you are trying to minimize? – mm8