シンプルなアプリで私の問題を説明しようとしています:
TextBlock が 1 つだけの MainWindow があります。この TextBlock のプロパティ テキストは、クラス CTimer のプロパティ Seconds にバインドされます。MainWindow には、1 秒ごとに 1 つの単純なことを行う DispatcherTimer もあります。つまり、オブジェクトの Seconds プロパティをインクリメントします。
MainWindow.xaml:
<Window x:Class="Try.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock Name="txtTime" Text="{Binding Seconds}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16" FontWeight="Bold"/>
</Grid>
</Window>
MainWindow.xaml.cs:
public partial class MainWindow : Window
{
private CTimer timer = new CTimer();
private DispatcherTimer ticker = new DispatcherTimer();
public MainWindow()
{
InitializeComponent();
ticker.Tick += AddSeconds;
ticker.Interval = TimeSpan.FromSeconds(1);
txtTime.DataContext = timer;
ticker.Start();
}
public void AddSeconds(object sender, EventArgs e)
{
timer.Seconds++;
}
}
CTimer.cs:
public class CTimer:INotifyPropertyChanged
{
private int seconds = 0;
public int Seconds
{
get { return seconds; }
set
{
seconds = value;
OnPropertyChanged("Seconds");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
私の問題 - 3 つのウィンドウ ボタン (最小/最大/閉じる) のいずれかを押したままにすると、DispatcherTimer が一時停止し、押したボタンを離すまで一時停止したままになります。
誰かがこの動作の原因を知っていますか?