mirror of https://github.com/AMT-Cheif/Stylet.git
Use MessageBox in the integration tests and samples
This commit is contained in:
parent
d1ab2d3cbd
commit
719653079a
|
@ -9,6 +9,8 @@ namespace Stylet.Samples.Hello
|
|||
{
|
||||
class ShellViewModel : Screen
|
||||
{
|
||||
private IWindowManager windowManager;
|
||||
|
||||
private string _name;
|
||||
public string Name
|
||||
{
|
||||
|
@ -16,9 +18,10 @@ namespace Stylet.Samples.Hello
|
|||
set { SetAndNotify(ref this._name, value); this.NotifyOfPropertyChange(() => this.CanSayHello); }
|
||||
}
|
||||
|
||||
public ShellViewModel()
|
||||
public ShellViewModel(IWindowManager windowManager)
|
||||
{
|
||||
this.DisplayName = "Hello, Stylet";
|
||||
this.windowManager = windowManager;
|
||||
}
|
||||
|
||||
public bool CanSayHello
|
||||
|
@ -27,7 +30,7 @@ namespace Stylet.Samples.Hello
|
|||
}
|
||||
public void SayHello()
|
||||
{
|
||||
MessageBox.Show(String.Format("Hello, {0}", this.Name)); // Don't do this
|
||||
this.windowManager.ShowMessageBox(String.Format("Hello, {0}", this.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,6 @@ namespace Stylet.Samples.ModelValidation.Pages
|
|||
{
|
||||
public class ShellViewModel : Conductor<IScreen>
|
||||
{
|
||||
public ShellViewModel()
|
||||
{
|
||||
this.ActiveItem = new UserViewModel(new FluentModelValidator<UserViewModel>(new UserViewModelValidator()));
|
||||
}
|
||||
|
||||
public ShellViewModel(UserViewModel userViewModel)
|
||||
{
|
||||
this.DisplayName = "Stylet.Samples.ModelValidation";
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace Stylet.Samples.ModelValidation.Pages
|
|||
{
|
||||
public class UserViewModel : Screen
|
||||
{
|
||||
private IWindowManager windowManager;
|
||||
|
||||
public string UserName { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
@ -21,8 +23,9 @@ namespace Stylet.Samples.ModelValidation.Pages
|
|||
set { this.autoValidate = value; this.NotifyOfPropertyChange(); }
|
||||
}
|
||||
|
||||
public UserViewModel(IModelValidator<UserViewModel> validator) : base(validator)
|
||||
public UserViewModel(IWindowManager windowManager, IModelValidator<UserViewModel> validator) : base(validator)
|
||||
{
|
||||
this.windowManager = windowManager;
|
||||
}
|
||||
|
||||
protected override void OnValidationStateChanged(IEnumerable<string> changedProperties)
|
||||
|
@ -39,7 +42,7 @@ namespace Stylet.Samples.ModelValidation.Pages
|
|||
public void Submit()
|
||||
{
|
||||
if (this.Validate())
|
||||
System.Windows.MessageBox.Show("Successfully submitted");
|
||||
this.windowManager.ShowMessageBox("Successfully submitted", "success");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,30 @@ namespace Stylet.Samples.ModelValidation.Xaml
|
|||
{
|
||||
public static class Secure
|
||||
{
|
||||
private static bool passwordInitialized;
|
||||
private static bool settingPassword;
|
||||
private static bool GetPasswordInitialized(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(PasswordInitializedProperty);
|
||||
}
|
||||
private static void SetPasswordInitialized(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(PasswordInitializedProperty, value);
|
||||
}
|
||||
// Using a DependencyProperty as the backing store for PasswordInitialized. This enables animation, styling, binding, etc...
|
||||
private static readonly DependencyProperty PasswordInitializedProperty =
|
||||
DependencyProperty.RegisterAttached("PasswordInitialized", typeof(bool), typeof(Secure), new PropertyMetadata(false));
|
||||
|
||||
|
||||
private static bool GetSettingPassword(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(SettingPasswordProperty);
|
||||
}
|
||||
private static void SetSettingPassword(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(SettingPasswordProperty, value);
|
||||
}
|
||||
// Using a DependencyProperty as the backing store for SettingPassword. This enables animation, styling, binding, etc...
|
||||
private static readonly DependencyProperty SettingPasswordProperty =
|
||||
DependencyProperty.RegisterAttached("SettingPassword", typeof(bool), typeof(Secure), new PropertyMetadata(false));
|
||||
|
||||
public static string GetPassword(DependencyObject obj)
|
||||
{
|
||||
|
@ -39,17 +61,17 @@ namespace Stylet.Samples.ModelValidation.Xaml
|
|||
|
||||
private static void HandleBoundPasswordChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (settingPassword)
|
||||
return;
|
||||
|
||||
var passwordBox = dp as PasswordBox;
|
||||
if (passwordBox == null)
|
||||
return;
|
||||
|
||||
if (GetSettingPassword(passwordBox))
|
||||
return;
|
||||
|
||||
// If this is the initial set
|
||||
if (!passwordInitialized)
|
||||
if (!GetPasswordInitialized(passwordBox))
|
||||
{
|
||||
passwordInitialized = true;
|
||||
SetPasswordInitialized(passwordBox, true);
|
||||
passwordBox.PasswordChanged += HandlePasswordChanged;
|
||||
}
|
||||
|
||||
|
@ -59,14 +81,38 @@ namespace Stylet.Samples.ModelValidation.Xaml
|
|||
private static void HandlePasswordChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var passwordBox = (PasswordBox)sender;
|
||||
settingPassword = true;
|
||||
SetSettingPassword(passwordBox, true);
|
||||
SetPassword(passwordBox, passwordBox.Password);
|
||||
settingPassword = false;
|
||||
SetSettingPassword(passwordBox, false);
|
||||
}
|
||||
|
||||
|
||||
private static bool securePasswordInitialized;
|
||||
private static bool settingSecurePassword;
|
||||
private static bool GetSecurePasswordInitialized(DependencyObject obj)
|
||||
{
|
||||
return (bool )obj.GetValue(SecurePasswordInitializedProperty);
|
||||
}
|
||||
private static void SetSecurePasswordInitialized(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(SecurePasswordInitializedProperty, value);
|
||||
}
|
||||
// Using a DependencyProperty as the backing store for SecurePasswordInitialized. This enables animation, styling, binding, etc...
|
||||
private static readonly DependencyProperty SecurePasswordInitializedProperty =
|
||||
DependencyProperty.RegisterAttached("SecurePasswordInitialized", typeof(bool ), typeof(Secure), new PropertyMetadata(false));
|
||||
|
||||
private static bool GetSettingSecurePassword(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(SettingSecurePasswordProperty);
|
||||
}
|
||||
|
||||
private static void SetSettingSecurePassword(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(SettingSecurePasswordProperty, value);
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for SettingSecurePassword. This enables animation, styling, binding, etc...
|
||||
private static readonly DependencyProperty SettingSecurePasswordProperty =
|
||||
DependencyProperty.RegisterAttached("SettingSecurePassword", typeof(bool), typeof(Secure), new PropertyMetadata(false));
|
||||
|
||||
|
||||
public static SecureString GetSecurePassword(DependencyObject obj)
|
||||
{
|
||||
|
@ -89,26 +135,26 @@ namespace Stylet.Samples.ModelValidation.Xaml
|
|||
|
||||
private static void HandleBoundSecurePasswordChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (settingSecurePassword)
|
||||
return;
|
||||
|
||||
var passwordBox = dp as PasswordBox;
|
||||
if (passwordBox == null)
|
||||
return;
|
||||
|
||||
if (!securePasswordInitialized)
|
||||
if (GetSettingSecurePassword(passwordBox))
|
||||
return;
|
||||
|
||||
if (!GetSecurePasswordInitialized(passwordBox))
|
||||
{
|
||||
passwordBox.PasswordChanged += HandleSecurePasswordChanged;
|
||||
securePasswordInitialized = true;
|
||||
SetSecurePasswordInitialized(passwordBox, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleSecurePasswordChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var passwordBox = (PasswordBox)sender;
|
||||
settingSecurePassword = true;
|
||||
SetSettingSecurePassword(passwordBox, true);
|
||||
SetSecurePassword(passwordBox, passwordBox.SecurePassword);
|
||||
settingSecurePassword = false;
|
||||
SetSettingSecurePassword(passwordBox, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Stylet
|
|||
/// <param name="defaultButton">Button pressed when the user presses Enter. Defaults to the leftmost button</param>
|
||||
/// <param name="cancelButton">Button pressed when the user preses Esc or clicks the red X on the titlebar. Defaults to the rightmost button</param>
|
||||
/// <returns>Which button the user clicked</returns>
|
||||
public static MessageBoxResult ShowMessageBox(this IWindowManager windowManager, string text, string title, MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultButton = MessageBoxResult.None, MessageBoxResult cancelButton = MessageBoxResult.None)
|
||||
public static MessageBoxResult ShowMessageBox(this IWindowManager windowManager, string text, string title = null, MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultButton = MessageBoxResult.None, MessageBoxResult cancelButton = MessageBoxResult.None)
|
||||
{
|
||||
var vm = IoC.Get<IMessageBoxViewModel>();
|
||||
vm.Setup(text, title, buttons, icon, defaultButton, cancelButton);
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace StyletIntegrationTests
|
|||
|
||||
public void ShowWindowLifecycle()
|
||||
{
|
||||
var window = new WindowLifecycle.WindowViewModel();
|
||||
var window = new WindowLifecycle.WindowViewModel(this.windowManager);
|
||||
this.windowManager.ShowWindow(window);
|
||||
}
|
||||
|
||||
|
@ -60,9 +60,9 @@ namespace StyletIntegrationTests
|
|||
await Task.Delay(100);
|
||||
|
||||
if (log.SequenceEqual(new[] { "One", "Two", "Four", "Three" }))
|
||||
MessageBox.Show("Success");
|
||||
this.windowManager.ShowMessageBox("Success");
|
||||
else
|
||||
MessageBox.Show("Failure");
|
||||
this.windowManager.ShowMessageBox("Failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,16 @@ namespace StyletIntegrationTests.WindowLifecycle
|
|||
{
|
||||
public class WindowViewModel : Screen
|
||||
{
|
||||
private IWindowManager windowManager;
|
||||
|
||||
public BindableCollection<string> Log { get; private set; }
|
||||
|
||||
public WindowViewModel()
|
||||
public WindowViewModel(IWindowManager windowManager)
|
||||
{
|
||||
this.DisplayName = "Window Lifecycle";
|
||||
|
||||
this.windowManager = windowManager;
|
||||
|
||||
this.Log = new BindableCollection<string>();
|
||||
}
|
||||
|
||||
|
@ -41,7 +45,7 @@ namespace StyletIntegrationTests.WindowLifecycle
|
|||
|
||||
protected override void OnClose()
|
||||
{
|
||||
MessageBox.Show("Closed");
|
||||
this.windowManager.ShowMessageBox("Closed", "Closed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue