Stylet/StyletIntegrationTests/ShellViewModel.cs

75 lines
2.3 KiB
C#
Raw Normal View History

2014-04-04 05:04:53 -07:00
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2014-05-10 12:11:02 -07:00
using System.Windows;
2014-04-04 05:04:53 -07:00
namespace StyletIntegrationTests
{
public class ShellViewModel : Screen
{
private readonly IWindowManager windowManager;
2014-04-04 05:04:53 -07:00
public ShellViewModel(IWindowManager windowManager)
{
this.windowManager = windowManager;
this.DisplayName = "ShellViewModel";
}
2014-04-04 05:04:53 -07:00
private bool? _showDialogAndDialogResultDialogResult;
public bool? ShowDialogAndDialogResultDialogResult
{
get { return this._showDialogAndDialogResultDialogResult; }
set { SetAndNotify(ref this._showDialogAndDialogResultDialogResult, value); }
}
public void ShowDialogAndDialogResult()
{
var dialog = new ShowDialogAndDialogResult.DialogViewModel();
this.ShowDialogAndDialogResultDialogResult = this.windowManager.ShowDialog(dialog);
}
public void ShowWindowLifecycle()
{
var window = new WindowLifecycle.WindowViewModel(this.windowManager);
2014-04-04 05:04:53 -07:00
this.windowManager.ShowWindow(window);
}
2014-05-10 12:11:02 -07:00
public void ThrowException()
{
2014-05-10 12:11:02 -07:00
throw new Exception("Hello");
}
2014-05-10 12:11:02 -07:00
public async void TestDispatcher()
2014-05-09 07:43:55 -07:00
{
2014-05-10 12:11:02 -07:00
var dispatcher = Execute.Dispatcher;
var log = new List<string>();
2014-05-09 07:43:55 -07:00
2014-05-10 12:11:02 -07:00
await Task.Run(() => dispatcher.Send(() => { lock(log) { log.Add("One"); }; }));
lock (log) { log.Add("Two"); };
await Task.Run(() => dispatcher.Post(() => { lock (log) { log.Add("Three"); }; }));
lock (log) { log.Add("Four"); };
// OK, so at this point there's a queued message saying to add Three to the log
// Give the main thread time to process that message
await Task.Delay(100);
if (log.SequenceEqual(new[] { "One", "Two", "Four", "Three" }))
this.windowManager.ShowMessageBox("Success", icon: MessageBoxImage.Information);
2014-05-10 12:11:02 -07:00
else
this.windowManager.ShowMessageBox("Failure");
}
public void ShowActionTargetSaved()
{
this.windowManager.ShowMessageBox("Success!");
}
}
2014-04-04 05:04:53 -07:00
}