i have a PopUp control whose IsOpen property is bound to a property named IsOpen in a ViewModel that realizes the INotifyPropertyChanged, i want the PopUp control to close or open automatically according to value of the IsOpen of the ViewModel,i use the MVVM patterm, the code as follow:
code in the ViewModel:
public class MainViewModel : ViewModelBase
{
private bool _isOpen;
public bool IsOpen
{
get
{
return this._isOpen;
}
set
{
if (this._isOpen != value)
{
this._isOpen = value;
RaisePropertyChanged("IsOpen");
}
}
}
}
code in the View:
//The Main is an instance of the MainViewModel below
Popup x:Name=”popUp” IsOpen=”{Binding Main.IsOpen}”
of course, there is a method in the ViewModel that used to changed the IsOpen property,i can see its change clearly,but it does not notify the view,did i miss something?thanks in advance.
I would create a User Control for that popup and an VM for that Control. Then I would create an instance of that user control and VM and show it from my main view model. This way you can have control over popup’s view model too.
This solution is overengineering if you want to show just a basic popup window though.