Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
db3f3ac
Initial PasswordBox "revealed" styles
nicolaihenriksen Aug 23, 2022
135cee0
Fixed alignment and initial wiring up
nicolaihenriksen Aug 23, 2022
f6e44e6
Showcasing style in sample app + alignment of reveal button
nicolaihenriksen Aug 23, 2022
66f1834
Showcase that password can still be set from XAML
nicolaihenriksen Aug 23, 2022
8d9c4f7
Change PasswordChanged event handler to weak event pattern
nicolaihenriksen Aug 24, 2022
22c0d31
Updated showcasing in the demo tool with a bit more stuff
nicolaihenriksen Aug 24, 2022
dd93d4a
Fixed CA warning
nicolaihenriksen Aug 24, 2022
9396459
Added UI test for 3-way binding
nicolaihenriksen Aug 29, 2022
df940a8
[Icon update detected by Github Action]. Auto generated pull request.…
github-actions[bot] Aug 30, 2022
8361fb8
Cursor fix (#2832)
nicolaihenriksen Aug 30, 2022
76eab1e
Fixed embedded dialog host style (#2826) (#2829)
Erapchu Aug 30, 2022
e6f81bf
Fix for 2596 - Align left margin for error message on outlined TextBo…
nicolaihenriksen Aug 30, 2022
6a08d55
Let DataGridCell handle mouse events itself when already editing (#2821)
nicolaihenriksen Aug 30, 2022
13b2483
Refactoring DataGridAssist input handling (#2824)
nicolaihenriksen Aug 30, 2022
63fed76
Initial PasswordBox "revealed" styles
nicolaihenriksen Aug 23, 2022
7798000
Fixed alignment and initial wiring up
nicolaihenriksen Aug 23, 2022
17aacdd
Showcasing style in sample app + alignment of reveal button
nicolaihenriksen Aug 23, 2022
1506b49
Showcase that password can still be set from XAML
nicolaihenriksen Aug 23, 2022
293f9cf
Change PasswordChanged event handler to weak event pattern
nicolaihenriksen Aug 24, 2022
a3c60ba
Updated showcasing in the demo tool with a bit more stuff
nicolaihenriksen Aug 24, 2022
438eae1
Fixed CA warning
nicolaihenriksen Aug 24, 2022
e0d208d
Added UI test for 3-way binding
nicolaihenriksen Aug 29, 2022
a7f23a4
Resolving merge conflicts
nicolaihenriksen Aug 30, 2022
cb8bbd1
Merge remote-tracking branch 'origin/featureRevealPasswordBox' into f…
nicolaihenriksen Aug 30, 2022
52c3c23
Resolving merge conflicts
nicolaihenriksen Aug 30, 2022
7b2c56e
Fixing hint proxy issues with password box
Keboo Aug 30, 2022
87070e3
Moved samples and added SMTX wrapper
nicolaihenriksen Aug 30, 2022
0f8187a
Apply cursor fix
nicolaihenriksen Aug 31, 2022
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
Prev Previous commit
Next Next commit
Fixing hint proxy issues with password box
  • Loading branch information
Keboo committed Aug 30, 2022
commit 7b2c56e36f6a801569174d013f52f8bb176e132e
86 changes: 40 additions & 46 deletions MainDemo.Wpf/Domain/DemoItem.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,55 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace MaterialDesignDemo.Domain;

namespace MaterialDesignDemo.Domain
public class DemoItem : ViewModelBase
{
public class DemoItem : ViewModelBase
{
private readonly Type _contentType;
private readonly object? _dataContext;
private readonly Type _contentType;
private readonly object? _dataContext;

private object? _content;
private ScrollBarVisibility _horizontalScrollBarVisibilityRequirement;
private ScrollBarVisibility _verticalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto;
private Thickness _marginRequirement = new(16);
private object? _content;
private ScrollBarVisibility _horizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto;
private ScrollBarVisibility _verticalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto;
private Thickness _marginRequirement = new(16);

public DemoItem(string name, Type contentType, IEnumerable<DocumentationLink> documentation, object? dataContext = null)
{
Name = name;
_contentType = contentType;
_dataContext = dataContext;
Documentation = documentation;
}
public DemoItem(string name, Type contentType, IEnumerable<DocumentationLink> documentation, object? dataContext = null)
{
Name = name;
_contentType = contentType;
_dataContext = dataContext;
Documentation = documentation;
}

public string Name { get; }
public string Name { get; }

public IEnumerable<DocumentationLink> Documentation { get; }
public IEnumerable<DocumentationLink> Documentation { get; }

public object? Content => _content ??= CreateContent();
public object? Content => _content ??= CreateContent();

public ScrollBarVisibility HorizontalScrollBarVisibilityRequirement
{
get => _horizontalScrollBarVisibilityRequirement;
set => SetProperty(ref _horizontalScrollBarVisibilityRequirement, value);
}
public ScrollBarVisibility HorizontalScrollBarVisibilityRequirement
{
get => _horizontalScrollBarVisibilityRequirement;
set => SetProperty(ref _horizontalScrollBarVisibilityRequirement, value);
}

public ScrollBarVisibility VerticalScrollBarVisibilityRequirement
{
get => _verticalScrollBarVisibilityRequirement;
set => SetProperty(ref _verticalScrollBarVisibilityRequirement, value);
}
public ScrollBarVisibility VerticalScrollBarVisibilityRequirement
{
get => _verticalScrollBarVisibilityRequirement;
set => SetProperty(ref _verticalScrollBarVisibilityRequirement, value);
}

public Thickness MarginRequirement
{
get => _marginRequirement;
set => SetProperty(ref _marginRequirement, value);
}
public Thickness MarginRequirement
{
get => _marginRequirement;
set => SetProperty(ref _marginRequirement, value);
}

private object? CreateContent()
private object? CreateContent()
{
var content = Activator.CreateInstance(_contentType);
if (_dataContext != null && content is FrameworkElement element)
{
var content = Activator.CreateInstance(_contentType);
if (_dataContext != null && content is FrameworkElement element)
{
element.DataContext = _dataContext;
}

return content;
element.DataContext = _dataContext;
}

return content;
}
}
31 changes: 13 additions & 18 deletions MaterialDesignThemes.Wpf/Converters/HintProxyFabricConverter.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Globalization;
using System.Windows.Data;

namespace MaterialDesignThemes.Wpf.Converters
namespace MaterialDesignThemes.Wpf.Converters;

/// <summary>
/// Converter for <see cref="SmartHint"/> control. Can be extended by <see cref="HintProxyFabric.RegisterBuilder(Func{Control, bool}, Func{Control, IHintProxy})"/> method.
/// </summary>
public class HintProxyFabricConverter : IValueConverter
{
/// <summary>
/// Converter for <see cref="SmartHint"/> control. Can be extended by <see cref="HintProxyFabric.RegisterBuilder(Func{Control, bool}, Func{Control, IHintProxy})"/> method.
/// </summary>
public class HintProxyFabricConverter : IValueConverter
{
private static readonly Lazy<HintProxyFabricConverter> _instance = new Lazy<HintProxyFabricConverter>();
private static readonly Lazy<HintProxyFabricConverter> _instance = new();

public static HintProxyFabricConverter Instance => _instance.Value;
public static HintProxyFabricConverter Instance => _instance.Value;

public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return HintProxyFabric.Get(value as Control);
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
=> HintProxyFabric.Get(value as Control);

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> Binding.DoNothing;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> Binding.DoNothing;
}
85 changes: 36 additions & 49 deletions MaterialDesignThemes.Wpf/HintProxyFabric.PasswordBox.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,55 @@
using System;
using System.Windows.Controls;
namespace MaterialDesignThemes.Wpf;

namespace MaterialDesignThemes.Wpf
public static partial class HintProxyFabric
{
public static partial class HintProxyFabric
private sealed class PasswordBoxHintProxy : IHintProxy
{
private sealed class PasswordBoxHintProxy : IHintProxy
{
private readonly PasswordBox _passwordBox;

public bool IsEmpty() => string.IsNullOrEmpty(_passwordBox.Password);
private readonly PasswordBox _passwordBox;

public object Content => _passwordBox.Password;
public bool IsEmpty() => string.IsNullOrEmpty(_passwordBox.Password);

public bool IsLoaded => _passwordBox.IsLoaded;
public object Content => _passwordBox.Password;

public bool IsVisible => _passwordBox.IsVisible;
public bool IsLoaded => _passwordBox.IsLoaded;

public bool IsFocused() => _passwordBox.IsKeyboardFocused;
public bool IsVisible => _passwordBox.IsVisible;

public event EventHandler? ContentChanged;
public event EventHandler? IsVisibleChanged;
public event EventHandler? Loaded;
public event EventHandler? FocusedChanged;
public bool IsFocused() => _passwordBox.IsKeyboardFocusWithin;

public PasswordBoxHintProxy(PasswordBox passwordBox)
{
if (passwordBox is null) throw new ArgumentNullException(nameof(passwordBox));
public event EventHandler? ContentChanged;
public event EventHandler? IsVisibleChanged;
public event EventHandler? Loaded;
public event EventHandler? FocusedChanged;

_passwordBox = passwordBox;
_passwordBox.PasswordChanged += PasswordBoxPasswordChanged;
_passwordBox.Loaded += PasswordBoxLoaded;
_passwordBox.IsVisibleChanged += PasswordBoxIsVisibleChanged;
_passwordBox.IsKeyboardFocusedChanged += PasswordBoxIsKeyboardFocusedChanged;
}
public PasswordBoxHintProxy(PasswordBox passwordBox)
{
if (passwordBox is null) throw new ArgumentNullException(nameof(passwordBox));

private void PasswordBoxIsKeyboardFocusedChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
FocusedChanged?.Invoke(this, EventArgs.Empty);
}
_passwordBox = passwordBox;
_passwordBox.PasswordChanged += PasswordBoxPasswordChanged;
_passwordBox.Loaded += PasswordBoxLoaded;
_passwordBox.IsVisibleChanged += PasswordBoxIsVisibleChanged;
_passwordBox.IsKeyboardFocusWithinChanged += PasswordBoxIsKeyboardFocusedChanged;
}

private void PasswordBoxIsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
IsVisibleChanged?.Invoke(this, EventArgs.Empty);
}
private void PasswordBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
=> FocusedChanged?.Invoke(this, EventArgs.Empty);

private void PasswordBoxLoaded(object sender, System.Windows.RoutedEventArgs e)
{
Loaded?.Invoke(this, EventArgs.Empty);
}
private void PasswordBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
=> IsVisibleChanged?.Invoke(this, EventArgs.Empty);

private void PasswordBoxPasswordChanged(object sender, System.Windows.RoutedEventArgs e)
{
ContentChanged?.Invoke(this, EventArgs.Empty);
}
private void PasswordBoxLoaded(object sender, RoutedEventArgs e)
=> Loaded?.Invoke(this, EventArgs.Empty);

public void Dispose()
{
_passwordBox.PasswordChanged -= PasswordBoxPasswordChanged;
_passwordBox.Loaded -= PasswordBoxLoaded;
_passwordBox.IsVisibleChanged -= PasswordBoxIsVisibleChanged;
_passwordBox.IsKeyboardFocusedChanged -= PasswordBoxIsKeyboardFocusedChanged;
}
private void PasswordBoxPasswordChanged(object sender, RoutedEventArgs e)
=> ContentChanged?.Invoke(this, EventArgs.Empty);

public void Dispose()
{
_passwordBox.PasswordChanged -= PasswordBoxPasswordChanged;
_passwordBox.Loaded -= PasswordBoxLoaded;
_passwordBox.IsVisibleChanged -= PasswordBoxIsVisibleChanged;
_passwordBox.IsKeyboardFocusWithinChanged -= PasswordBoxIsKeyboardFocusedChanged;
}
}
}
73 changes: 34 additions & 39 deletions MaterialDesignThemes.Wpf/HintProxyFabric.TextBox.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
using System;
using System.Windows;
using System.Windows.Controls;
namespace MaterialDesignThemes.Wpf;

namespace MaterialDesignThemes.Wpf
public static partial class HintProxyFabric
{
public static partial class HintProxyFabric
private sealed class TextBoxHintProxy : IHintProxy
{
private sealed class TextBoxHintProxy : IHintProxy
{
private readonly TextBox _textBox;
private readonly TextBox _textBox;

public bool IsLoaded => _textBox.IsLoaded;
public bool IsLoaded => _textBox.IsLoaded;

public bool IsVisible => _textBox.IsVisible;
public bool IsVisible => _textBox.IsVisible;

public bool IsEmpty() => string.IsNullOrEmpty(_textBox.Text);
public bool IsEmpty() => string.IsNullOrEmpty(_textBox.Text);

public bool IsFocused() => _textBox.IsKeyboardFocused;
public bool IsFocused() => _textBox.IsKeyboardFocusWithin;

public event EventHandler? ContentChanged;
public event EventHandler? IsVisibleChanged;
public event EventHandler? Loaded;
public event EventHandler? FocusedChanged;
public event EventHandler? ContentChanged;
public event EventHandler? IsVisibleChanged;
public event EventHandler? Loaded;
public event EventHandler? FocusedChanged;

public TextBoxHintProxy(TextBox textBox)
{
_textBox = textBox ?? throw new ArgumentNullException(nameof(textBox));
_textBox.TextChanged += TextBoxTextChanged;
_textBox.Loaded += TextBoxLoaded;
_textBox.IsVisibleChanged += TextBoxIsVisibleChanged;
_textBox.IsKeyboardFocusedChanged += TextBoxIsKeyboardFocusedChanged;
}
public TextBoxHintProxy(TextBox textBox)
{
_textBox = textBox ?? throw new ArgumentNullException(nameof(textBox));
_textBox.TextChanged += TextBoxTextChanged;
_textBox.Loaded += TextBoxLoaded;
_textBox.IsVisibleChanged += TextBoxIsVisibleChanged;
_textBox.IsKeyboardFocusWithinChanged += TextBoxIsKeyboardFocusedChanged;
}

private void TextBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
=> FocusedChanged?.Invoke(sender, EventArgs.Empty);
private void TextBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
=> FocusedChanged?.Invoke(sender, EventArgs.Empty);

private void TextBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
=> IsVisibleChanged?.Invoke(sender, EventArgs.Empty);
private void TextBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
=> IsVisibleChanged?.Invoke(sender, EventArgs.Empty);

private void TextBoxLoaded(object sender, RoutedEventArgs e)
=> Loaded?.Invoke(sender, EventArgs.Empty);
private void TextBoxLoaded(object sender, RoutedEventArgs e)
=> Loaded?.Invoke(sender, EventArgs.Empty);

private void TextBoxTextChanged(object sender, TextChangedEventArgs e)
=> ContentChanged?.Invoke(sender, EventArgs.Empty);
private void TextBoxTextChanged(object sender, TextChangedEventArgs e)
=> ContentChanged?.Invoke(sender, EventArgs.Empty);

public void Dispose()
{
_textBox.TextChanged -= TextBoxTextChanged;
_textBox.Loaded -= TextBoxLoaded;
_textBox.IsVisibleChanged -= TextBoxIsVisibleChanged;
_textBox.IsKeyboardFocusedChanged -= TextBoxIsKeyboardFocusedChanged;
}
public void Dispose()
{
_textBox.TextChanged -= TextBoxTextChanged;
_textBox.Loaded -= TextBoxLoaded;
_textBox.IsVisibleChanged -= TextBoxIsVisibleChanged;
_textBox.IsKeyboardFocusWithinChanged -= TextBoxIsKeyboardFocusedChanged;
}
}
}
Loading