Merge pull request #756 from irihitech/fix-multicombobox-items-in-axaml
feat: simplify closable tag.
This commit is contained in:
@@ -135,14 +135,7 @@
|
|||||||
Command="{TemplateBinding Command}"
|
Command="{TemplateBinding Command}"
|
||||||
CommandParameter="{TemplateBinding}"
|
CommandParameter="{TemplateBinding}"
|
||||||
Content="{StaticResource ClosableTagCloseIconGlyph}" />
|
Content="{StaticResource ClosableTagCloseIconGlyph}" />
|
||||||
<Border
|
|
||||||
IsVisible="{TemplateBinding VisualContent, Converter={x:Static ObjectConverters.IsNotNull}}"
|
|
||||||
Background="{TemplateBinding VisualContent}"
|
|
||||||
Width="{TemplateBinding VisualContentWidth}"
|
|
||||||
Height="{TemplateBinding VisualContentHeight}"
|
|
||||||
IsHitTestVisible="False" />
|
|
||||||
<ContentPresenter
|
<ContentPresenter
|
||||||
IsVisible="{TemplateBinding VisualContent, Converter={x:Static ObjectConverters.IsNull}}"
|
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
Content="{TemplateBinding Content}"
|
Content="{TemplateBinding Content}"
|
||||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ public class MultiComboBox : SelectingItemsControl, IInnerContentControl, IPopup
|
|||||||
{
|
{
|
||||||
if (o is StyledElement s)
|
if (o is StyledElement s)
|
||||||
{
|
{
|
||||||
var data = s is ClosableTag { VisualContent: not null } c ? c.Content : s.DataContext;
|
var data = s.DataContext;
|
||||||
SelectedItems?.Remove(data);
|
SelectedItems?.Remove(data);
|
||||||
var item = Items.FirstOrDefault(a => ReferenceEquals(a, data));
|
var item = Items.FirstOrDefault(a => ReferenceEquals(a, data));
|
||||||
if (item is not null)
|
if (item is not null)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Shapes;
|
||||||
using Avalonia.Layout;
|
using Avalonia.Layout;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
|
||||||
@@ -35,12 +36,18 @@ public class MultiComboBoxSelectedItemList: ItemsControl
|
|||||||
tag.Command = RemoveCommand;
|
tag.Command = RemoveCommand;
|
||||||
if (item is Layoutable visualContent)
|
if (item is Layoutable visualContent)
|
||||||
{
|
{
|
||||||
tag.VisualContent = new VisualBrush
|
var visualBrush = new VisualBrush
|
||||||
{
|
{
|
||||||
Visual = visualContent,
|
Visual = visualContent,
|
||||||
};
|
};
|
||||||
tag.VisualContentWidth = visualContent.Bounds.Width;
|
var rectangle = new Rectangle()
|
||||||
tag.VisualContentHeight = visualContent.Bounds.Height;
|
{
|
||||||
|
Fill = visualBrush,
|
||||||
|
Width = visualContent.Bounds.Width,
|
||||||
|
Height = visualContent.Bounds.Height,
|
||||||
|
};
|
||||||
|
tag.Content = rectangle;
|
||||||
|
tag.DataContext = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,36 +14,9 @@ public class ClosableTag : ContentControl
|
|||||||
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<ClosableTag, ICommand?>(
|
public static readonly StyledProperty<ICommand?> CommandProperty = AvaloniaProperty.Register<ClosableTag, ICommand?>(
|
||||||
nameof(Command));
|
nameof(Command));
|
||||||
|
|
||||||
public static readonly StyledProperty<VisualBrush?> VisualContentProperty = AvaloniaProperty.Register<ClosableTag, VisualBrush?>(
|
|
||||||
nameof(VisualContent));
|
|
||||||
|
|
||||||
public static readonly StyledProperty<double?> VisualContentWidthProperty = AvaloniaProperty.Register<ClosableTag, double?>(
|
|
||||||
nameof(VisualContentWidth));
|
|
||||||
|
|
||||||
public static readonly StyledProperty<double?> VisualContentHeightProperty = AvaloniaProperty.Register<ClosableTag, double?>(
|
|
||||||
nameof(VisualContentHeight));
|
|
||||||
|
|
||||||
public ICommand? Command
|
public ICommand? Command
|
||||||
{
|
{
|
||||||
get => GetValue(CommandProperty);
|
get => GetValue(CommandProperty);
|
||||||
set => SetValue(CommandProperty, value);
|
set => SetValue(CommandProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VisualBrush? VisualContent
|
|
||||||
{
|
|
||||||
get => GetValue(VisualContentProperty);
|
|
||||||
set => SetValue(VisualContentProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double? VisualContentWidth
|
|
||||||
{
|
|
||||||
get => GetValue(VisualContentWidthProperty);
|
|
||||||
set => SetValue(VisualContentWidthProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double? VisualContentHeight
|
|
||||||
{
|
|
||||||
get => GetValue(VisualContentHeightProperty);
|
|
||||||
set => SetValue(VisualContentHeightProperty, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user