离线状态下,设置按钮的不可用。通过改变资源字典的值。
App.xaml 文件下添加如下
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<sys:Boolean x:Key="IsOnline1">true</sys:Boolean>
App.xaml.cs 下添加
public App()
{
//StartIsOnlineCheck();
this.Startup += App_Startup; } void App_Startup(object sender, StartupEventArgs e)
{
StartIsOnlineCheck();
//throw new NotImplementedException();
} public void ChangeIsOnlineRes()
{
this.Resources["IsOnline1"] = IsOnline;
}
private void StartIsOnlineCheck()
{
Timer2 = new Timer(new TimerCallback((o) =>
{
IsOnline = !IsOnline;
ChangeIsOnlineRes();
}
), null, 0, 1000 * 10);
}
要用到的地方
<Button Width="130" Height="48" Content="tttttttttttt" IsEnabled="{DynamicResource IsOnline1}" />