【发布时间】:2014-04-21 06:35:44
【问题描述】:
下面是我的代码,
public partial class MainWindow : Window, INotifyPropertyChanged
{
private int myHeight = 0;
public int MyHeight
{
get { return myHeight; }
set
{
myHeight = value;
OnPropertyChanged("MyHeight");
MessageBox.Show("MainWindowHeight" + MyHeight);
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}
private void OnPropertyChanged(string prop)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
<Window x:Class="Window_Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="{Binding MyHeight, Mode=TwoWay}" Width="525">
<Grid>
</Grid>
</Window>
当我将窗口状态从最小化更改为最大化时,setter 被调用了两次,第一次它具有正确的实际值,而在第二次调用中它的值是 38,对这种行为有什么解释吗?还有为什么它会被调用两次?
谢谢, 库马尔
【问题讨论】: