WPF绑定变量的时候,只有第一次加载的时候,界面会刷新,后续可以通过通知UI的方式来更新数据

        public static string DateTimeNow => DateTime.Now.ToString("G");

        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;//静态事件处理属性更改
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(DateTimeNow)));
                //DateTimeNow = DateTime.Now.ToString("G");
                    Task.Delay(1000).Wait();
                }
            });


        }
如果觉得我的文章对你有用,请随意赞赏