zoukankan      html  css  js  c++  java
  • wpf,离线状态下部分功能不可用。

    离线状态下,设置按钮的不可用。通过改变资源字典的值。

     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}" />

    例子Demo

  • 相关阅读:
    2019 Multi-University Training Contest 10
    自考新教材-p326_3(1)
    自考新教材-p322
    自考新教材-p321
    自考新教材-p316
    自考新教材-p315
    自考新教材-p313
    自考新教材-p311
    自考新教材-p310
    自考新教材-p309
  • 原文地址:https://www.cnblogs.com/m7777/p/5266541.html
Copyright © 2011-2022 走看看