私の wpf アプリケーションでは、イベントの startDate と endDate があります。ポップアップ アラート ボックスを実装して、endDate が近づいたときに警告メッセージを自動的に表示したいと思います (たとえば、endDate の 5 日前)。ClientDeadlines (私の wpf の ItemTab ヘッダー)をクリックしたときのスクリーンショットでは、アラート ボックスが表示されます。どうすればこの機能を実現できますか? どんなサンプルでも大歓迎です。前もって感謝します。
3070 次
2 に答える
1
WPF では、System.Windows.Threading. で DispatcherTimer を使用できます。
DispatcherTimer timer = new DispatcherTimer();
DateTime myDeadLine = new DateTime();
public void InitTimer()
{
// Checks every minute
timer.Interval = new TimeSpan(0, 1, 0);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if ((myDeadLine - DateTime.Now).TotalDays <= 5)
MessageBox.Show("Your Alert Message");
}
EDIT : ユーザーが ClientDeadLines をクリックするたびに警告メッセージを表示するには、TabControl のSelectionChangedイベントを購読します。
<TabControl SelectionChanged="TabControl_SelectionChanged_1" HorizontalAlignment="Left" Height="100" Margin="46,90,0,0" VerticalAlignment="Top" Width="397">
<TabItem Name="Tab1" Header="Check1">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Name="ClientDeadLines" Header="Check2" Height="23" VerticalAlignment="Bottom">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
そして、このコードビハインドを使用してください
private void TabControl_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
if (e.Source is TabControl)
{
if (ClientDeadLines.IsSelected)
{
// Your code to check time
int a = 0;
}
}
}
于 2013-08-27T09:20:43.253 に答える