I have two windows, I want to hide the one that is executing the opening of the 2nd window.
ViewModel:
public class MainWindowViewModel : INotifyPropertyChanged
{
private bool _isVisible;
public bool isVisible
{
get { return _isVisible; }
set
{
_isVisible = value;
NotifyOfPropertyChange("isVisible");
}
}
public MainWindowViewModel()
{
Window1 X = new Window1();
isVisible = false;
X.Show();
}
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyOfPropertyChange(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
The XAML:
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
</Window.Resources>
<Window.Visibility>
<Binding Path="isVisible" Converter="{StaticResource BooleanToVisibilityConverter}" />
</Window.Visibility>
The new window is showing however the one that is supposed to get hidden is still there and I can't manage to understand why it's happening.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…