Merge pull request #194 from irihitech/issues/192

Fix Multi ComboBox issues.
This commit is contained in:
Dong Bin
2024-03-27 22:06:47 +08:00
committed by GitHub
5 changed files with 16 additions and 4 deletions

View File

@@ -17,7 +17,8 @@
InnerLeftContent="Left" InnerLeftContent="Left"
InnerRightContent="Right" InnerRightContent="Right"
Classes="ClearButton" Classes="ClearButton"
ItemsSource="{Binding Items}" /> ItemsSource="{Binding Items}" >
</u:MultiComboBox>
<ListBox ItemsSource="{Binding #combo.SelectedItems}" /> <ListBox ItemsSource="{Binding #combo.SelectedItems}" />
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@@ -50,6 +50,7 @@
HorizontalScrollBarVisibility="Disabled"> HorizontalScrollBarVisibility="Disabled">
<u:MultiComboBoxSelectedItemList <u:MultiComboBoxSelectedItemList
VerticalAlignment="Center" VerticalAlignment="Center"
ItemTemplate="{TemplateBinding SelectedItemTemplate}"
ItemsSource="{TemplateBinding SelectedItems}" ItemsSource="{TemplateBinding SelectedItems}"
RemoveCommand="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Remove}"> RemoveCommand="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Remove}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>

View File

@@ -121,11 +121,12 @@
Data="{DynamicResource ClosableTagCloseIconGlyph}" Data="{DynamicResource ClosableTagCloseIconGlyph}"
DockPanel.Dock="Right" DockPanel.Dock="Right"
Foreground="{TemplateBinding Foreground}" /> Foreground="{TemplateBinding Foreground}" />
<TextBlock <ContentPresenter
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
FontSize="12" FontSize="12"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Content}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
TextTrimming="CharacterEllipsis" /> TextTrimming="CharacterEllipsis" />
</DockPanel> </DockPanel>
</Border> </Border>

View File

@@ -79,6 +79,15 @@ public class MultiComboBox: SelectingItemsControl, IInnerContentControl
get => GetValue(InnerRightContentProperty); get => GetValue(InnerRightContentProperty);
set => SetValue(InnerRightContentProperty, value); set => SetValue(InnerRightContentProperty, value);
} }
public static readonly StyledProperty<IDataTemplate?> SelectedItemTemplateProperty = AvaloniaProperty.Register<MultiComboBox, IDataTemplate?>(
nameof(SelectedItemTemplate));
public IDataTemplate? SelectedItemTemplate
{
get => GetValue(SelectedItemTemplateProperty);
set => SetValue(SelectedItemTemplateProperty, value);
}
static MultiComboBox() static MultiComboBox()
{ {

View File

@@ -87,7 +87,7 @@ public class MultiComboBoxItem: ContentControl
e.InitialPressMouseButton is MouseButton.Left or MouseButton.Right) e.InitialPressMouseButton is MouseButton.Left or MouseButton.Right)
{ {
var point = e.GetCurrentPoint(this); var point = e.GetCurrentPoint(this);
if (new Rect(Bounds.Size).ContainsExclusive(point.Position)) if (new Rect(Bounds.Size).ContainsExclusive(point.Position) && e.Pointer.Type == PointerType.Touch)
{ {
this.IsSelected = !this.IsSelected; this.IsSelected = !this.IsSelected;
e.Handled = true; e.Handled = true;