Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions MahApps.Metro/Controls/Dialogs/LoginDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class LoginDialogSettings : MetroDialogSettings
private const Visibility DefaultNegativeButtonVisibility = Visibility.Collapsed;
private const bool DefaultShouldHideUsername = false;
private const bool DefaultEnablePasswordPreview = false;
private const Visibility DefaultRememberCheckBoxVisibility = Visibility.Collapsed;
private const string DefaultRememberCheckBoxText = "Remember";

public LoginDialogSettings()
{
Expand All @@ -21,6 +23,8 @@ public LoginDialogSettings()
ShouldHideUsername = DefaultShouldHideUsername;
AffirmativeButtonText = "Login";
EnablePasswordPreview = DefaultEnablePasswordPreview;
RememberCheckBoxVisibility = DefaultRememberCheckBoxVisibility;
RememberCheckBoxText = DefaultRememberCheckBoxText;
}

public string InitialUsername { get; set; }
Expand All @@ -36,12 +40,17 @@ public LoginDialogSettings()
public Visibility NegativeButtonVisibility { get; set; }

public bool EnablePasswordPreview { get; set; }

public Visibility RememberCheckBoxVisibility { get; set; }

public string RememberCheckBoxText { get; set; }
}

public class LoginDialogData
{
public string Username { get; set; }
public string Password { get; set; }
public string Username { get; internal set; }
public string Password { get; internal set; }
public bool ShouldRemember { get; internal set; }
}

public partial class LoginDialog : BaseMetroDialog
Expand All @@ -61,6 +70,8 @@ internal LoginDialog(MetroWindow parentWindow, LoginDialogSettings settings)
PasswordWatermark = settings.PasswordWatermark;
NegativeButtonButtonVisibility = settings.NegativeButtonVisibility;
ShouldHideUsername = settings.ShouldHideUsername;
RememberCheckBoxVisibility = settings.RememberCheckBoxVisibility;
RememberCheckBoxText = settings.RememberCheckBoxText;
}

internal Task<LoginDialogData> WaitForButtonPressAsync()
Expand Down Expand Up @@ -136,7 +147,7 @@ internal Task<LoginDialogData> WaitForButtonPressAsync()
if (e.Key == Key.Enter)
{
cleanUpHandlers();
tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password });
tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ShouldRemember = RememberCheckBoxChecked });
}
};

Expand All @@ -153,7 +164,7 @@ internal Task<LoginDialogData> WaitForButtonPressAsync()
{
cleanUpHandlers();

tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password });
tcs.TrySetResult(new LoginDialogData { Username = Username, Password = PART_TextBox2.Password, ShouldRemember = RememberCheckBoxChecked });

e.Handled = true;
};
Expand Down Expand Up @@ -206,6 +217,9 @@ protected override void OnLoaded()
public static readonly DependencyProperty NegativeButtonTextProperty = DependencyProperty.Register("NegativeButtonText", typeof(string), typeof(LoginDialog), new PropertyMetadata("Cancel"));
public static readonly DependencyProperty NegativeButtonButtonVisibilityProperty = DependencyProperty.Register("NegativeButtonButtonVisibility", typeof(Visibility), typeof(LoginDialog), new PropertyMetadata(Visibility.Collapsed));
public static readonly DependencyProperty ShouldHideUsernameProperty = DependencyProperty.Register("ShouldHideUsername", typeof(bool), typeof(LoginDialog), new PropertyMetadata(false));
public static readonly DependencyProperty RememberCheckBoxVisibilityProperty = DependencyProperty.Register("RememberCheckBoxVisibility", typeof(Visibility), typeof(LoginDialog), new PropertyMetadata(Visibility.Collapsed));
public static readonly DependencyProperty RememberCheckBoxTextProperty = DependencyProperty.Register("RememberCheckBoxText", typeof(string), typeof(LoginDialog), new PropertyMetadata("Remember"));
public static readonly DependencyProperty RememberCheckBoxCheckedProperty = DependencyProperty.Register("RememberCheckBoxChecked", typeof(bool), typeof(LoginDialog), new PropertyMetadata(false));

public string Message
{
Expand Down Expand Up @@ -260,5 +274,23 @@ public bool ShouldHideUsername
get { return (bool)GetValue(ShouldHideUsernameProperty); }
set { SetValue(ShouldHideUsernameProperty, value); }
}

public Visibility RememberCheckBoxVisibility
{
get { return (Visibility)GetValue(RememberCheckBoxVisibilityProperty); }
set { SetValue(RememberCheckBoxVisibilityProperty, value); }
}

public string RememberCheckBoxText
{
get { return (string)GetValue(RememberCheckBoxTextProperty); }
set { SetValue(RememberCheckBoxTextProperty, value); }
}

public bool RememberCheckBoxChecked
{
get { return (bool)GetValue(RememberCheckBoxCheckedProperty); }
set { SetValue(RememberCheckBoxCheckedProperty, value); }
}
}
}
10 changes: 9 additions & 1 deletion MahApps.Metro/Themes/Dialogs/LoginDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="0 5 0 0"
Expand All @@ -37,7 +38,14 @@
Controls:TextBoxHelper.Watermark="{Binding PasswordWatermark, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
Controls:TextBoxHelper.SelectAllOnFocus="True"
Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
<StackPanel Grid.Row="3"
<CheckBox Grid.Row="3"
Margin="0 5 0 0"
FontSize="{DynamicResource DialogMessageFontSize}"
x:Name="PART_RememberCheckBox"
Visibility="{Binding RememberCheckBoxVisibility, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
Content="{Binding RememberCheckBoxText, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
IsChecked="{Binding RememberCheckBoxChecked, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
<StackPanel Grid.Row="4"
Orientation="Horizontal"
HorizontalAlignment="Right"
Height="85">
Expand Down
22 changes: 12 additions & 10 deletions samples/MetroDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
d:DesignHeight="600"
d:DesignWidth="800"
d:DataContext="{d:DesignInstance MetroDemo:MainWindowViewModel}"
Closing="MetroWindow_Closing"
Dialog:DialogParticipation.Register="{Binding}">
<!--
Closing="MetroWindow_Closing"
Dialog:DialogParticipation.Register="{Binding}">
<!--
if using DialogParticipation on Windows which open/close frequently you will get a
memory leak unless you unregister. The easiest way to do this is in your Closing/Unloaded
memory leak unless you unregister. The easiest way to do this is in your Closing/Unloaded
event, as so:

DialogParticipation.SetRegister(this, null);
-->
-->

<Window.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -81,15 +81,15 @@
<Dialog:CustomDialog x:Key="CustomCloseDialogTest"
Title="Custom Dialog which is awaitable"
x:Name="CustomCloseDialogTest">

<StackPanel>
<TextBlock Height="30" Text="This dialog allows arbitrary content. You have to close it yourself by clicking the close button below."
<TextBlock Height="30" Text="This dialog allows arbitrary content. You have to close it yourself by clicking the close button below."
TextWrapping="Wrap"
Foreground="{DynamicResource AccentColorBrush}" />
<Button Content="Close Me!" Click="CloseCustomDialog"/>
</StackPanel>


</Dialog:CustomDialog>

</ResourceDictionary>
Expand Down Expand Up @@ -177,6 +177,8 @@
Header="Show Password Preview LoginDialog" />
<MenuItem Click="ShowLoginDialogOnlyPassword"
Header="Show LoginDialog (Only Password)" />
<MenuItem Click="ShowLoginDialogWithRememberCheckBox"
Header="Show LoginDialog (With Remember CheckBox)" />
<MenuItem Click="ShowMessageDialog"
Header="Show MessageDialog" />
<MenuItem Click="ShowLimitedMessageDialog"
Expand Down Expand Up @@ -255,7 +257,7 @@
<exampleViews:OtherExamples DataContext="{Binding}" />
</TabItem>
</Controls:MetroAnimatedSingleRowTabControl>

<StatusBar Grid.Row="2">
<StatusBarItem>MahApps.Metro DEMO Application</StatusBarItem>
<Separator Style="{StaticResource MetroStatusBarSeparator}" />
Expand Down
13 changes: 13 additions & 0 deletions samples/MetroDemo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ private async void ShowLoginDialogOnlyPassword(object sender, RoutedEventArgs e)
}
}

private async void ShowLoginDialogWithRememberCheckBox(object sender, RoutedEventArgs e)
{
LoginDialogData result = await this.ShowLoginAsync("Authentication", "Enter your password", new LoginDialogSettings { ColorScheme = this.MetroDialogOptions.ColorScheme, RememberCheckBoxVisibility = Visibility.Visible });
if (result == null)
{
//User pressed cancel
}
else
{
MessageDialogResult messageResult = await this.ShowMessageAsync("Authentication Information", String.Format("Username: {0}\nPassword: {1}\nShouldRemember: {2}", result.Username, result.Password, result.ShouldRemember));
}
}

private async void ShowProgressDialog(object sender, RoutedEventArgs e)
{
var controller = await this.ShowProgressAsync("Please wait...", "We are baking some cupcakes!");
Expand Down