diff --git a/MainDemo.Wpf/Converters/ColorToBrushConverter.cs b/MainDemo.Wpf/Converters/ColorToBrushConverter.cs index 7052879845..3c6ac31ffd 100644 --- a/MainDemo.Wpf/Converters/ColorToBrushConverter.cs +++ b/MainDemo.Wpf/Converters/ColorToBrushConverter.cs @@ -7,16 +7,18 @@ namespace MaterialDesignDemo.Converters; [ValueConversion(typeof(Color), typeof(Brush))] public class ColorToBrushConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is Color color) { - return new SolidColorBrush(color); + SolidColorBrush rv = new(color); + rv.Freeze(); + return rv; } return Binding.DoNothing; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is SolidColorBrush brush) { diff --git a/MainDemo.Wpf/Domain/FieldsViewModel.cs b/MainDemo.Wpf/Domain/FieldsViewModel.cs index 699ca7f65e..414010eeec 100644 --- a/MainDemo.Wpf/Domain/FieldsViewModel.cs +++ b/MainDemo.Wpf/Domain/FieldsViewModel.cs @@ -1,5 +1,7 @@ -namespace MaterialDesignDemo.Domain; +using System.Collections.ObjectModel; +using System.Windows.Media; +namespace MaterialDesignDemo.Domain; public class FieldsViewModel : ViewModelBase { private string? _name; @@ -10,6 +12,12 @@ public class FieldsViewModel : ViewModelBase private string? _password2Validated = "pre-filled"; private string? _text1; private string? _text2; + private ObservableCollection? _autoSuggestBox1Suggestions; + private string? _autoSuggestBox1Text; + private readonly List? _originalAutoSuggestBox1Suggestions; + private ObservableCollection>? _autoSuggestBox2Suggestions; + private string? _autoSuggestBox2Text; + private readonly List>? _originalAutoSuggestBox2Suggestions; public string? Name { @@ -71,6 +79,46 @@ public string? Password2Validated public FieldsTestObject TestObject => new() { Name = "Mr. Test" }; + public ObservableCollection? AutoSuggestBox1Suggestions + { + get => _autoSuggestBox1Suggestions; + set => SetProperty(ref _autoSuggestBox1Suggestions, value); + } + + public ObservableCollection>? AutoSuggestBox2Suggestions + { + get => _autoSuggestBox2Suggestions; + set => SetProperty(ref _autoSuggestBox2Suggestions, value); + } + + public string? AutoSuggestBox1Text + { + get => _autoSuggestBox1Text; + set + { + if (SetProperty(ref _autoSuggestBox1Text, value) && + _originalAutoSuggestBox1Suggestions != null && value != null) + { + var searchResult = _originalAutoSuggestBox1Suggestions.Where(x => IsMatch(x, value)); + AutoSuggestBox1Suggestions = new ObservableCollection(searchResult); + } + } + } + + public string? AutoSuggestBox2Text + { + get => _autoSuggestBox2Text; + set + { + if (SetProperty(ref _autoSuggestBox2Text, value) && + _originalAutoSuggestBox2Suggestions != null && value != null) + { + var searchResult = _originalAutoSuggestBox2Suggestions.Where(x => IsMatch(x.Key, value)); + AutoSuggestBox2Suggestions = new ObservableCollection>(searchResult); + } + } + } + public ICommand SetPassword1FromViewModelCommand { get; } public ICommand SetPassword2FromViewModelCommand { get; } @@ -78,6 +126,34 @@ public FieldsViewModel() { SetPassword1FromViewModelCommand = new AnotherCommandImplementation(_ => Password1 = "Set from ViewModel!"); SetPassword2FromViewModelCommand = new AnotherCommandImplementation(_ => Password2 = "Set from ViewModel!"); + + _originalAutoSuggestBox1Suggestions = new List() + { + "Burger", "Fries", "Shake", "Lettuce" + }; + + _originalAutoSuggestBox2Suggestions = new List>(GetColors()); + + AutoSuggestBox1Suggestions = new ObservableCollection(_originalAutoSuggestBox1Suggestions); + } + + private static bool IsMatch(string item, string currentText) + { +#if NET6_0_OR_GREATER + return item.Contains(currentText, StringComparison.OrdinalIgnoreCase); +#else + return item.IndexOf(currentText, StringComparison.OrdinalIgnoreCase) >= 0; +#endif + } + + private static IEnumerable> GetColors() + { + return typeof(Colors) + .GetProperties() + .Where(prop => + typeof(Color).IsAssignableFrom(prop.PropertyType)) + .Select(prop => + new KeyValuePair(prop.Name, (Color)prop.GetValue(null)!)); } } diff --git a/MainDemo.Wpf/Fields.xaml b/MainDemo.Wpf/Fields.xaml index 6ee2767681..d6c74d3e0e 100644 --- a/MainDemo.Wpf/Fields.xaml +++ b/MainDemo.Wpf/Fields.xaml @@ -1,6 +1,7 @@ + + + + + + + + + + diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml index e21deed4b2..dac32f6d50 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml @@ -2,7 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - @@ -42,6 +41,7 @@ + diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml index fd63482248..9728528298 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml @@ -19,50 +19,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + @@ -75,10 +43,8 @@ - + @@ -195,8 +161,8 @@ + VerticalAlignment="Stretch" + HorizontalAlignment="Stretch"> @@ -221,10 +187,10 @@ + UseFloating="{TemplateBinding wpf:HintAssist.IsFloating}" + VerticalAlignment="Stretch" + VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" + HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"> - + - + @@ -344,7 +306,7 @@ - + @@ -354,7 +316,7 @@ - + @@ -426,7 +388,7 @@ - + @@ -621,18 +583,18 @@