feat: 1. update container state from selection collection change.

2. Add popup slot.
3. fix various binding relative resource issue.
4. update empty pseudo-class handing, simplify watermark visibility.
This commit is contained in:
rabbitism
2024-08-24 12:59:58 +08:00
parent fc26ec7ce5
commit dffdcf3aa3
5 changed files with 174 additions and 95 deletions

View File

@@ -12,6 +12,12 @@
x:DataType="vm:MultiComboBoxDemoViewModel"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal">
<u:MultiComboBox
Watermark="Please Select"
MaxHeight="200"
SelectedItems="{Binding SelectedItems}"
ItemsSource="{Binding Items}" >
</u:MultiComboBox>
<u:MultiComboBox
Name="combo"
Watermark="Please Select"
@@ -19,8 +25,21 @@
InnerRightContent="Right"
Classes="ClearButton"
MaxHeight="200"
SelectedItems="{Binding SelectedItems}"
ItemsSource="{Binding Items}" >
<u:MultiComboBox.PopupInnerTopContent>
<StackPanel Margin="0" Orientation="Horizontal">
<Button Theme="{DynamicResource BorderlessButton}" Content="Select All" Command="{Binding SelectAllCommand}"/>
<Button Theme="{DynamicResource BorderlessButton}" Content="Unselect All" Command="{Binding ClearAllCommand}"/>
<Button Theme="{DynamicResource BorderlessButton}" Content="Inverse" Command="{Binding InvertSelectionCommand}"/>
</StackPanel>
</u:MultiComboBox.PopupInnerTopContent>
<u:MultiComboBox.ContextFlyout>
<MenuFlyout>
<MenuItem Header="Select All" Command="{Binding SelectAllCommand}"/>
</MenuFlyout>
</u:MultiComboBox.ContextFlyout>
</u:MultiComboBox>
<ListBox ItemsSource="{Binding #combo.SelectedItems}" />
<ListBox ItemsSource="{Binding SelectedItems}" />
</StackPanel>
</UserControl>

View File

@@ -1,12 +1,44 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace Ursa.Demo.ViewModels;
public class MultiComboBoxDemoViewModel: ObservableObject
{
public ObservableCollection<string> Items { get; set; }
public ObservableCollection<string> SelectedItems { get; set; }
public ICommand SelectAllCommand => new RelayCommand(() =>
{
SelectedItems.Clear();
foreach (var item in Items)
{
SelectedItems.Add(item);
}
});
public ICommand ClearAllCommand => new RelayCommand(() =>
{
SelectedItems.Clear();
});
public ICommand InvertSelectionCommand => new RelayCommand(() =>
{
var selectedItems = new List<string>(SelectedItems);
SelectedItems.Clear();
foreach (var item in Items)
{
if (!selectedItems.Contains(item))
{
SelectedItems.Add(item);
}
}
});
public MultiComboBoxDemoViewModel()
{
Items = new ObservableCollection<string>()
@@ -47,5 +79,6 @@ public class MultiComboBoxDemoViewModel: ObservableObject
"Pennsylvania",
"Rhode Island",
};
SelectedItems = new ObservableCollection<string>();
}
}