feat: add a simple template.

This commit is contained in:
rabbitism
2024-03-24 16:45:29 +08:00
parent d271623a66
commit d91a17474c
3 changed files with 24 additions and 3 deletions

View File

@@ -4,6 +4,26 @@
<!-- Add Resources Here -->
<ControlTheme TargetType="u:MultiComboBox" x:Key="{x:Type u:MultiComboBox}">
<Setter Property="Focusable" Value="True"></Setter>
<Setter Property="Template">
<ControlTemplate TargetType="u:MultiComboBox">
<Panel>
<ToggleButton Name="button">
<ItemsControl ItemsSource="{TemplateBinding SelectedItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ToggleButton>
<Popup PlacementTarget="button" IsOpen="{Binding #button.IsChecked}">
<ListBox SelectionMode="Multiple" ItemsSource="{TemplateBinding ItemsSource}" SelectedItems="{TemplateBinding SelectedItems}">
</ListBox>
</Popup>
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>
<ControlTheme TargetType="u:MultiComboBoxItem" x:Key="{x:Type u:MultiComboBoxItem}">

View File

@@ -20,6 +20,7 @@
<ResourceInclude Source="KeyGestureInput.axaml" />
<ResourceInclude Source="Loading.axaml" />
<ResourceInclude Source="MessageBox.axaml" />
<ResourceInclude Source="MultiComboBox.axaml" />
<ResourceInclude Source="NavMenu.axaml" />
<ResourceInclude Source="NumericUpDown.axaml" />
<ResourceInclude Source="NumPad.axaml" />

View File

@@ -1,4 +1,6 @@
using System.Collections.ObjectModel;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
@@ -8,8 +10,6 @@ namespace Ursa.Controls;
public class MultiComboBox: SelectingItemsControl
{
private ComboBox _box;
private static ITemplate<Panel?> _defaultPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
public static readonly StyledProperty<bool> IsDropDownOpenProperty =