feat: WIP add a demo.
This commit is contained in:
14
demo/Ursa.Demo/Pages/MultiComboBoxDemo.axaml
Normal file
14
demo/Ursa.Demo/Pages/MultiComboBoxDemo.axaml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||||
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
|
x:DataType="vm:MultiComboBoxDemoViewModel"
|
||||||
|
x:CompileBindings="True"
|
||||||
|
x:Class="Ursa.Demo.Pages.MultiComboBoxDemo">
|
||||||
|
<StackPanel>
|
||||||
|
<u:MultiComboBox ItemsSource="{Binding Items}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
13
demo/Ursa.Demo/Pages/MultiComboBoxDemo.axaml.cs
Normal file
13
demo/Ursa.Demo/Pages/MultiComboBoxDemo.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.Pages;
|
||||||
|
|
||||||
|
public partial class MultiComboBoxDemo : UserControl
|
||||||
|
{
|
||||||
|
public MultiComboBoxDemo()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,6 +43,7 @@ public class MainViewViewModel : ViewModelBase
|
|||||||
MenuKeys.MenuKeyKeyGestureInput => new KeyGestureInputDemoViewModel(),
|
MenuKeys.MenuKeyKeyGestureInput => new KeyGestureInputDemoViewModel(),
|
||||||
MenuKeys.MenuKeyLoading => new LoadingDemoViewModel(),
|
MenuKeys.MenuKeyLoading => new LoadingDemoViewModel(),
|
||||||
MenuKeys.MenuKeyMessageBox => new MessageBoxDemoViewModel(),
|
MenuKeys.MenuKeyMessageBox => new MessageBoxDemoViewModel(),
|
||||||
|
MenuKeys.MenuKeyMultiComboBox => new MultiComboBoxDemoViewModel(),
|
||||||
MenuKeys.MenuKeyNavMenu => new NavMenuDemoViewModel(),
|
MenuKeys.MenuKeyNavMenu => new NavMenuDemoViewModel(),
|
||||||
MenuKeys.MenuKeyNumberDisplayer => new NumberDisplayerDemoViewModel(),
|
MenuKeys.MenuKeyNumberDisplayer => new NumberDisplayerDemoViewModel(),
|
||||||
MenuKeys.MenuKeyNumericUpDown => new NumericUpDownDemoViewModel(),
|
MenuKeys.MenuKeyNumericUpDown => new NumericUpDownDemoViewModel(),
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class MenuViewModel: ViewModelBase
|
|||||||
new() { MenuHeader = "KeyGestureInput", Key = MenuKeys.MenuKeyKeyGestureInput },
|
new() { MenuHeader = "KeyGestureInput", Key = MenuKeys.MenuKeyKeyGestureInput },
|
||||||
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading },
|
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading },
|
||||||
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
||||||
|
new() { MenuHeader = "MultiComboBox", Key = MenuKeys.MenuKeyMultiComboBox, Status = "New" },
|
||||||
new() { MenuHeader = "Nav Menu", Key = MenuKeys.MenuKeyNavMenu, Status = "Updated" },
|
new() { MenuHeader = "Nav Menu", Key = MenuKeys.MenuKeyNavMenu, Status = "Updated" },
|
||||||
// new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
|
// new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
|
||||||
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
||||||
@@ -70,6 +71,7 @@ public static class MenuKeys
|
|||||||
public const string MenuKeyKeyGestureInput = "KeyGestureInput";
|
public const string MenuKeyKeyGestureInput = "KeyGestureInput";
|
||||||
public const string MenuKeyLoading = "Loading";
|
public const string MenuKeyLoading = "Loading";
|
||||||
public const string MenuKeyMessageBox = "MessageBox";
|
public const string MenuKeyMessageBox = "MessageBox";
|
||||||
|
public const string MenuKeyMultiComboBox = "MultiComboBox";
|
||||||
public const string MenuKeyNavMenu = "NavMenu";
|
public const string MenuKeyNavMenu = "NavMenu";
|
||||||
public const string MenuKeyNumberDisplayer = "NumberDisplayer";
|
public const string MenuKeyNumberDisplayer = "NumberDisplayer";
|
||||||
public const string MenuKeyNumericUpDown = "NumericUpDown";
|
public const string MenuKeyNumericUpDown = "NumericUpDown";
|
||||||
|
|||||||
30
demo/Ursa.Demo/ViewModels/MultiComboBoxDemoViewModel.cs
Normal file
30
demo/Ursa.Demo/ViewModels/MultiComboBoxDemoViewModel.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
|
public class MultiComboBoxDemoViewModel: ObservableObject
|
||||||
|
{
|
||||||
|
public ObservableCollection<string> Items { get; set; }
|
||||||
|
|
||||||
|
public MultiComboBoxDemoViewModel()
|
||||||
|
{
|
||||||
|
Items = new ObservableCollection<string>()
|
||||||
|
{
|
||||||
|
"Item 1",
|
||||||
|
"Item 2",
|
||||||
|
"Item 3",
|
||||||
|
"Item 4",
|
||||||
|
"Item 5",
|
||||||
|
"Item 6",
|
||||||
|
"Item 7",
|
||||||
|
"Item 8",
|
||||||
|
"Illinois",
|
||||||
|
"Indiana",
|
||||||
|
"Iowa",
|
||||||
|
"Kansas",
|
||||||
|
"Kentucky",
|
||||||
|
"Louisiana",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
<Popup PlacementTarget="button" IsOpen="{Binding #button.IsChecked}">
|
<Popup PlacementTarget="button" IsOpen="{Binding #button.IsChecked}">
|
||||||
<ListBox SelectionMode="Multiple" ItemsSource="{TemplateBinding ItemsSource}" SelectedItems="{TemplateBinding SelectedItems}">
|
<ListBox Name="{x:Static u:MultiComboBox.PART_ListBox}" SelectionMode="Multiple" ItemsSource="{TemplateBinding ItemsSource}" SelectedItems="{TemplateBinding SelectedItems}">
|
||||||
|
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</Popup>
|
</Popup>
|
||||||
|
|||||||
@@ -3,13 +3,18 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Metadata;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
[TemplatePart( PART_ListBox, typeof(ListBox))]
|
||||||
public class MultiComboBox: SelectingItemsControl
|
public class MultiComboBox: SelectingItemsControl
|
||||||
{
|
{
|
||||||
|
public const string PART_ListBox = "PART_ListBox";
|
||||||
|
private ListBox? _listBox;
|
||||||
|
|
||||||
private static ITemplate<Panel?> _defaultPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
|
private static ITemplate<Panel?> _defaultPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> IsDropDownOpenProperty =
|
public static readonly StyledProperty<bool> IsDropDownOpenProperty =
|
||||||
@@ -20,6 +25,15 @@ public class MultiComboBox: SelectingItemsControl
|
|||||||
get => GetValue(IsDropDownOpenProperty);
|
get => GetValue(IsDropDownOpenProperty);
|
||||||
set => SetValue(IsDropDownOpenProperty, value);
|
set => SetValue(IsDropDownOpenProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new static readonly StyledProperty<IList?> SelectedItemsProperty = AvaloniaProperty.Register<MultiComboBox, IList?>(
|
||||||
|
nameof(SelectedItems));
|
||||||
|
|
||||||
|
public new IList? SelectedItems
|
||||||
|
{
|
||||||
|
get => GetValue(SelectedItemsProperty);
|
||||||
|
set => SetValue(SelectedItemsProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
static MultiComboBox()
|
static MultiComboBox()
|
||||||
{
|
{
|
||||||
@@ -44,4 +58,22 @@ public class MultiComboBox: SelectingItemsControl
|
|||||||
dropDownItem.BringIntoView();
|
dropDownItem.BringIntoView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate(e);
|
||||||
|
_listBox = e.NameScope.Find<ListBox>(PART_ListBox);
|
||||||
|
if (_listBox != null)
|
||||||
|
{
|
||||||
|
_listBox.SelectionChanged += ListBox_SelectionChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender == _listBox)
|
||||||
|
{
|
||||||
|
this.SelectedItems = _listBox.SelectedItems;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user