空闲窗口页面WPF

时间:2014-04-30 10:07:24

标签: c# wpf xaml idle-timer

我检测到我的WPF项目不活动。我一直在使用这段代码。

 readonly DispatcherTimer activityTimer;


    public MainWindow()
    {
        InitializeComponent();

        InputManager.Current.PreProcessInput += Activity;

        activityTimer = new DispatcherTimer
        {
            Interval = TimeSpan.FromSeconds(5),
            IsEnabled = true
        };
        activityTimer.Tick += Inactivity;

    }

    #region
    void Inactivity(object sender, EventArgs e)
    {


        FrameBody.Source = new Uri("Pages/Body.xaml", UriKind.Relative);


    }

    void Activity(object sender, PreProcessInputEventArgs e)
    {
        activityTimer.Stop();
        activityTimer.Start();


    }
    #endregion

它确实有效,但只有一个问题。当用户不对系统做任何事情时,它确实改变了框架的来源 FrameBody.Source = new Uri(" Pages / Body.xaml",UriKind.Relative); 但它也是最近的框架来源。

在我的系统中,我使用了一个带框架的窗口。并且该帧的来源根据用户与系统的交互而改变。 (例如,当用户单击按钮时,该框架的源会发生变化,当鼠标没有单击或突然移动几秒钟/分钟时,框架的来源将发生变化。)

有谁能告诉我我的代码有什么问题?上面的代码基于此WPF inactivity and activity

0 个答案:

没有答案