自动保存 - WPF C#

car*_*y88 6 c# wpf

有没有一种方法可以保存ListView中的细节,不需要我每次都使用保存对话框,并允许我在一定的时间跨度内调用它.所以每次都"保存"而不是"另存为".

Gre*_*ora 6

您可以使用DispatchTimer与方法的回调来执行保存.

    DispatcherTimer autosaveTimer = new DispatcherTimer(TimeSpan.FromSeconds(autosaveInterval), DispatcherPriority.Background, new EventHandler(DoAutoSave), Application.Current.Dispatcher);

    private void DoAutoSave(object sender, EventArgs e)
    {
        // Enter save logic here...
    }
Run Code Online (Sandbox Code Playgroud)