feat: implement inner content interface.
This commit is contained in:
@@ -7,9 +7,11 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:DataType="vm:MultiAutoCompleteBoxDemoViewModel"
|
x:DataType="vm:MultiAutoCompleteBoxDemoViewModel"
|
||||||
x:Class="Ursa.Demo.Pages.MultiAutoCompleteBoxDemo">
|
x:Class="Ursa.Demo.Pages.MultiAutoCompleteBoxDemo">
|
||||||
<StackPanel Spacing="20">
|
<StackPanel Spacing="20" HorizontalAlignment="Left">
|
||||||
<TextBlock Text="Multi-AutoCompleteBox"/>
|
<TextBlock Text="Multi-AutoCompleteBox"/>
|
||||||
<u:MultiAutoCompleteBox ItemsSource="{Binding Items}"
|
<u:MultiAutoCompleteBox ItemsSource="{Binding Items}"
|
||||||
|
MaxWidth="400"
|
||||||
|
InnerLeftContent="Controls"
|
||||||
SelectedItems="{Binding SelectedItems}"
|
SelectedItems="{Binding SelectedItems}"
|
||||||
ItemFilter="{Binding FilterPredicate }"
|
ItemFilter="{Binding FilterPredicate }"
|
||||||
FilterMode="Custom">
|
FilterMode="Custom">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
@@ -82,12 +83,13 @@ public class MultiAutoCompleteBoxDemoViewModel: ObservableObject
|
|||||||
{
|
{
|
||||||
if (text is null) return true;
|
if (text is null) return true;
|
||||||
if (data is not ControlData control) return false;
|
if (data is not ControlData control) return false;
|
||||||
return control.MenuHeader.Contains(text )|| control.Chinese.Contains(text);
|
return control.MenuHeader.Contains(text, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
control.Chinese.Contains(text, StringComparison.InvariantCultureIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ControlData
|
public class ControlData
|
||||||
{
|
{
|
||||||
public string MenuHeader { get; set; }
|
public required string MenuHeader { get; init; }
|
||||||
public string Chinese { get; set; }
|
public required string Chinese { get; init; }
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,22 @@
|
|||||||
<Border
|
<Border
|
||||||
Name="PART_RootBorder"
|
Name="PART_RootBorder"
|
||||||
MinHeight="30"
|
MinHeight="30"
|
||||||
Padding="{DynamicResource TextBoxContentPadding}"
|
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
CornerRadius="{TemplateBinding CornerRadius}"
|
CornerRadius="{TemplateBinding CornerRadius}"
|
||||||
Background="{DynamicResource TextBoxDefaultBackground}"
|
Background="{DynamicResource TextBoxDefaultBackground}"
|
||||||
BorderBrush="{DynamicResource TextBoxDefaultBorderBrush}">
|
BorderBrush="{DynamicResource TextBoxDefaultBorderBrush}">
|
||||||
|
<Grid ColumnDefinitions="Auto, *, Auto">
|
||||||
|
<ContentPresenter
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="8,0"
|
||||||
|
IsHitTestVisible="False"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Content="{TemplateBinding InnerLeftContent}"
|
||||||
|
Foreground="{DynamicResource TextBoxInnerForeground}"
|
||||||
|
IsVisible="{TemplateBinding InnerLeftContent,
|
||||||
|
Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
<u:MultiComboBoxSelectedItemList
|
<u:MultiComboBoxSelectedItemList
|
||||||
|
Grid.Column="1"
|
||||||
Name="{x:Static u:MultiAutoCompleteBox.PART_SelectedItemsControl}"
|
Name="{x:Static u:MultiAutoCompleteBox.PART_SelectedItemsControl}"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
RemoveCommand="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Remove}"
|
RemoveCommand="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Remove}"
|
||||||
@@ -33,6 +43,16 @@
|
|||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</u:MultiComboBoxSelectedItemList.ItemsPanel>
|
</u:MultiComboBoxSelectedItemList.ItemsPanel>
|
||||||
</u:MultiComboBoxSelectedItemList>
|
</u:MultiComboBoxSelectedItemList>
|
||||||
|
<ContentPresenter
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="8,0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
IsHitTestVisible="False"
|
||||||
|
Content="{TemplateBinding InnerRightContent}"
|
||||||
|
Foreground="{DynamicResource TextBoxInnerForeground}"
|
||||||
|
IsVisible="{TemplateBinding InnerRightContent,
|
||||||
|
Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
<Popup
|
<Popup
|
||||||
Name="PART_Popup"
|
Name="PART_Popup"
|
||||||
@@ -49,12 +69,16 @@
|
|||||||
BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}"
|
BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}"
|
||||||
BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}"
|
BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}"
|
||||||
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}">
|
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}">
|
||||||
|
<DockPanel LastChildFill="True">
|
||||||
|
<ContentPresenter Content="{TemplateBinding PopupInnerTopContent}" DockPanel.Dock="Top" />
|
||||||
|
<ContentPresenter Content="{TemplateBinding PopupInnerBottomContent}" DockPanel.Dock="Bottom" />
|
||||||
<ListBox
|
<ListBox
|
||||||
Name="PART_SelectingItemsControl"
|
Name="PART_SelectingItemsControl"
|
||||||
Foreground="{TemplateBinding Foreground}"
|
Foreground="{TemplateBinding Foreground}"
|
||||||
ItemTemplate="{TemplateBinding ItemTemplate}"
|
ItemTemplate="{TemplateBinding ItemTemplate}"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||||
ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
||||||
|
</DockPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Popup>
|
</Popup>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|||||||
@@ -512,4 +512,22 @@ public partial class MultiAutoCompleteBox
|
|||||||
get => GetValue(InnerRightContentProperty);
|
get => GetValue(InnerRightContentProperty);
|
||||||
set => SetValue(InnerRightContentProperty, value);
|
set => SetValue(InnerRightContentProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<object?> PopupInnerTopContentProperty = AvaloniaProperty.Register<MultiAutoCompleteBox, object?>(
|
||||||
|
nameof(PopupInnerTopContent));
|
||||||
|
|
||||||
|
public object? PopupInnerTopContent
|
||||||
|
{
|
||||||
|
get => GetValue(PopupInnerTopContentProperty);
|
||||||
|
set => SetValue(PopupInnerTopContentProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<object?> PopupInnerBottomContentProperty = AvaloniaProperty.Register<MultiAutoCompleteBox, object?>(
|
||||||
|
nameof(PopupInnerBottomContent));
|
||||||
|
|
||||||
|
public object? PopupInnerBottomContent
|
||||||
|
{
|
||||||
|
get => GetValue(PopupInnerBottomContentProperty);
|
||||||
|
set => SetValue(PopupInnerBottomContentProperty, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ namespace Ursa.Controls;
|
|||||||
[TemplatePart(ElementSelectionAdapter, typeof(ISelectionAdapter))]
|
[TemplatePart(ElementSelectionAdapter, typeof(ISelectionAdapter))]
|
||||||
[TemplatePart(ElementTextBox, typeof(TextBox))]
|
[TemplatePart(ElementTextBox, typeof(TextBox))]
|
||||||
[PseudoClasses(":dropdownopen")]
|
[PseudoClasses(":dropdownopen")]
|
||||||
public partial class MultiAutoCompleteBox : TemplatedControl, IInnerContentControl
|
public partial class MultiAutoCompleteBox : TemplatedControl, IInnerContentControl, IPopupInnerContent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the name of the selection adapter TemplatePart.
|
/// Specifies the name of the selection adapter TemplatePart.
|
||||||
|
|||||||
Reference in New Issue
Block a user