I'm building WPF application using MaterialDesignInXaml together with ReactiveUI. I have the following XAML code:
<ItemsControl ItemsSource="{Binding Filters}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:FilterViewModel}">
<ComboBox
Margin="6,0,6,12"
materialDesign:HintAssist.HelperText="{Binding Name}"
materialDesign:HintAssist.Hint="{Binding Name}"
materialDesign:TextFieldAssist.HasClearButton="True" /// <--- clear button doesn't work!
ItemsSource="{Binding Options}"
SelectedItem="{Binding SelectedOption}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
And the corresponding ViewModel:
public class MainWindowViewModel : ReactiveObject
{
public List<FilterViewModel> Filters { get; set; } = new();
public MainWindowViewModel()
{
Filters = Enumerable.Range(1, 3).Select(x => new FilterViewModel()
{
Name = $"Filter {x}",
Options = new ObservableCollection<string>(Enumerable.Range(1, 5).Select(y => y.ToString()))
}).ToList();
}
}
public class FilterViewModel : ReactiveObject
{
public ObservableCollection<string> Options { get; set; } = new();
public string Name
{
get => _name;
set => this.RaiseAndSetIfChanged(ref _name, value);
}
public string SelectedOption
{
get => _selectedOption;
set => this.RaiseAndSetIfChanged(ref _selectedOption, value);
}
private string _selectedOption;
private string _name;
}
This gives me nice three ComboBoxes:
The problem is that ComboBox clear button has no effect when clicked. It simply dosn't do anything, no error, nothing. Am I missing something here? Why it doesn't work?
