Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a90e3c
Implement the AutoSuggestion in TextBox by using TextFieldAssist.Auto…
AbderrahmaneAhmam May 20, 2023
b3e1d3f
Fixing the code warnings about the null values
AbderrahmaneAhmam May 21, 2023
1e7552d
Fix warnings in the FieldsViewModel 0 Warning(s)
AbderrahmaneAhmam May 21, 2023
0f1bb1c
Add underscore prefix to the private properties
AbderrahmaneAhmam May 22, 2023
6d41235
Reset changes of the AutoSuggestion in the TextFieldAssist
AbderrahmaneAhmam May 27, 2023
d509195
creation of control AutoSuggestBox Based on TextBox with custom Templ…
AbderrahmaneAhmam Jun 19, 2023
dbaa4e3
Fix Warnings
AbderrahmaneAhmam Jun 19, 2023
e0d3ed0
Rebase build fixing
Keboo Aug 10, 2023
7d85d89
Adding some TODOs, starting on the UI tests
Keboo Aug 10, 2023
03ec8e4
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Aug 12, 2023
aa7b202
Merge branch 'master' of https://github.com/AbderrahmaneAhmam/Materia…
AbderrahmaneAhmam Aug 12, 2023
0fdfbd7
Merge branch 'feature/AutoSuggestion' of https://github.com/Abderrahm…
AbderrahmaneAhmam Aug 12, 2023
829e298
Remove AutoSuggestBox from properties
AbderrahmaneAhmam Aug 12, 2023
e6b148a
Implement the tests:
AbderrahmaneAhmam Aug 12, 2023
26f2c22
WIP showing sample test for ICollectionView
Keboo Aug 13, 2023
9946cab
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Aug 14, 2023
408708b
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Aug 17, 2023
8d8889e
Use ICollectionView for keyboard navigation and ensure completion of …
AbderrahmaneAhmam Sep 3, 2023
d47c665
rename key
AbderrahmaneAhmam Sep 3, 2023
e1f4419
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Sep 3, 2023
596f708
Merge branch 'master' of https://github.com/AbderrahmaneAhmam/Materia…
AbderrahmaneAhmam Sep 3, 2023
82bee7a
Merge branch 'feature/AutoSuggestion' of https://github.com/Abderrahm…
AbderrahmaneAhmam Sep 3, 2023
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
Next Next commit
Implement the AutoSuggestion in TextBox by using TextFieldAssist.Auto…
…SuggestionEnabled & ItemsSource
  • Loading branch information
AbderrahmaneAhmam authored and Keboo committed Aug 10, 2023
commit 2a90e3c590e8c708743af88f6f4b3dc4c4c11c8b
100 changes: 89 additions & 11 deletions MainDemo.Wpf/Domain/FieldsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MaterialDesignDemo.Domain;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Media;

public class FieldsViewModel : ViewModelBase
namespace MaterialDesignDemo.Domain
{
private string? _name;
private string? _name2;
Expand All @@ -13,9 +15,16 @@ public class FieldsViewModel : ViewModelBase

public string? Name
{
get => _name;
set => SetProperty(ref _name, value);
}
private string? _name;
private string? _name2;
private string? _password1 = string.Empty;
private string? _password2 = "pre-filled";
private string? _password1Validated = "pre-filled";
private string? _password2Validated = "pre-filled";
private string? _text1;
private string? _text2;
private string? _autoSuggestionTextBox1 = string.Empty;
private string? _autoSuggestionTextBox2 = string.Empty;

public string? Name2
{
Expand Down Expand Up @@ -71,13 +80,82 @@ public string? Password2Validated

public FieldsTestObject TestObject => new() { Name = "Mr. Test" };

public ICommand SetPassword1FromViewModelCommand { get; }
public ICommand SetPassword2FromViewModelCommand { get; }

public FieldsViewModel()
{
SetPassword1FromViewModelCommand = new AnotherCommandImplementation(_ => Password1 = "Set from ViewModel!");
SetPassword2FromViewModelCommand = new AnotherCommandImplementation(_ => Password2 = "Set from ViewModel!");
public string? AutoSuggestionTextBox1
{
get { return _autoSuggestionTextBox1; }
set { SetProperty(ref _autoSuggestionTextBox1, value); }
}


public string? AutoSuggestionTextBox2
{
get { return _autoSuggestionTextBox2; }
set { SetProperty(ref _autoSuggestionTextBox2, value); }
}


private ObservableCollection<string> listSuggestion;

public ObservableCollection<string> ListSuggestion
{
get { return listSuggestion; }
set { SetProperty(ref listSuggestion, value); }
}


private ObservableCollection<string> baseListSuggestion;

public ObservableCollection<string> BaseListSuggestion
{
get { return baseListSuggestion; }
set { SetProperty(ref baseListSuggestion, value); }
}

private ObservableCollection<KeyValuePair<string, Brush>> listColors;

public ObservableCollection<KeyValuePair<string, Brush>> ListColors
{
get { return listColors; }
set { SetProperty(ref listColors, value); }
}

public FieldsTestObject TestObject => new() { Name = "Mr. Test" };

public ICommand AutoSuggestionTextBox1ChangedCommand { get; }
public ICommand AutoSuggestionTextBox2ChangedCommand { get; }
public ICommand SetPassword1FromViewModelCommand { get; }
public ICommand SetPassword2FromViewModelCommand { get; }

public FieldsViewModel()
{
SetPassword1FromViewModelCommand = new AnotherCommandImplementation(_ => Password1 = "Set from ViewModel!");
SetPassword2FromViewModelCommand = new AnotherCommandImplementation(_ => Password2 = "Set from ViewModel!");
BaseListSuggestion = new ObservableCollection<string>()
{
"Burger", "Fries", "Shake", "Lettuce"
};
ListColors = new ObservableCollection<KeyValuePair<string, Brush>>(GetColors());
ListSuggestion = BaseListSuggestion;
AutoSuggestionTextBox1ChangedCommand = new AnotherCommandImplementation(_ =>
{
ListSuggestion = new ObservableCollection<string>(BaseListSuggestion.Where(s => s.ToLower().Contains(AutoSuggestionTextBox1.ToLower())));
});
AutoSuggestionTextBox2ChangedCommand = new AnotherCommandImplementation(_ =>
{
ListColors = new ObservableCollection<KeyValuePair<string, Brush>>(GetColors().Where(s => s.Key.StartsWith(AutoSuggestionTextBox2)));
});
}

private IEnumerable<KeyValuePair<string, Brush>> GetColors()
{
return typeof(Colors)
.GetProperties()
.Where(prop =>
typeof(Color).IsAssignableFrom(prop.PropertyType))
.Select(prop =>
new KeyValuePair<string, Brush>(prop.Name, new SolidColorBrush((Color)prop.GetValue(null))));
}
}
}

Expand Down
79 changes: 79 additions & 0 deletions MainDemo.Wpf/Fields.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:domain="clr-namespace:MaterialDesignDemo.Domain"
xmlns:domain1="clr-namespace:MaterialDesignDemo.Domain"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
Expand Down Expand Up @@ -757,5 +758,83 @@
</smtx:XamlDisplay>
</StackPanel>
</Grid>

<Grid Margin="0,48,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="0,0,0,10"
VerticalAlignment="Center"
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="TextBox With AutoSuggestion" />
<TextBlock Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Text="Simple source list" />
<smtx:XamlDisplay Grid.Row="2"
Grid.Column="0"
UniqueKey="fields_autosuggestion_1">
<TextBox materialDesign:TextFieldAssist.AutoSuggestionEnabled="True"
materialDesign:TextFieldAssist.AutoSuggestionItemsSource="{Binding ListSuggestion}"
Text="{Binding AutoSuggestionTextBox1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding AutoSuggestionTextBox1ChangedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</smtx:XamlDisplay>

<TextBlock Grid.Row="1"
Grid.Column="1"
Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Text="AutoSuggestionItemTemplate" />
<smtx:XamlDisplay Grid.Row="2"
Grid.Column="1"
UniqueKey="fields_autosuggestion_2">
<TextBox materialDesign:TextFieldAssist.AutoSuggestionEnabled="True"
materialDesign:TextFieldAssist.AutoSuggestionItemsSource="{Binding ListColors}"
materialDesign:TextFieldAssist.AutoSuggestionValueMember="Key"
materialDesign:ValidationAssist.HasError="False"
Text="{Binding AutoSuggestionTextBox2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding AutoSuggestionTextBox2ChangedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBox.Style>
<Style TargetType="TextBox" BasedOn="{StaticResource MaterialDesignTextBox}">
<Setter Property="Margin" Value="0,8" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="materialDesign:TextFieldAssist.AutoSuggestionItemTemplate">
<Setter.Value>
<DataTemplate>
<DockPanel>
<Border Width="20"
Height="20"
Background="{Binding Value}"
CornerRadius="10" />
<TextBlock Margin="10,0,0,0" Text="{Binding Key}" />
</DockPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TextBox.Style>
</TextBox>
</smtx:XamlDisplay>
</Grid>
</StackPanel>
</UserControl>
Loading