feat: selected item is now two-way binding by default.
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:iri="https://irihi.tech/shared"
|
||||
xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls">
|
||||
xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
|
||||
xmlns:converters1="clr-namespace:Ursa.Themes.Semi.Converters">
|
||||
<!-- Add Resources Here -->
|
||||
|
||||
<converters:MarginMultiplierConverter x:Key="LeftMarginConverter" Indent="20" Left="True"/>
|
||||
<converters1:SelectedItemTemplateConverter x:Key="SelectedItemTemplateConverter"/>
|
||||
|
||||
<ControlTheme x:Key="{x:Type u:TreeComboBox}" TargetType="u:TreeComboBox">
|
||||
<Setter Property="Padding" Value="{DynamicResource ComboBoxSelectorDefaultPadding}"/>
|
||||
@@ -17,7 +19,7 @@
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:TreeComboBox">
|
||||
<Grid ColumnDefinitions="*, Auto, 32">
|
||||
<Grid ColumnDefinitions="*, Auto, Auto">
|
||||
<Border Grid.Column="0"
|
||||
Name="Background"
|
||||
Grid.ColumnSpan="3"
|
||||
@@ -44,8 +46,14 @@
|
||||
Margin="{TemplateBinding Padding}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
VerticalAlignment="Center"
|
||||
ContentTemplate="{TemplateBinding SelectedItemTemplate}"
|
||||
Content="{TemplateBinding SelectionBoxItem}"/>
|
||||
Content="{TemplateBinding SelectionBoxItem}">
|
||||
<ContentPresenter.ContentTemplate>
|
||||
<MultiBinding Converter="{x:Static converters1:SelectedItemTemplateConverter.Instance}">
|
||||
<TemplateBinding Property="SelectedItemTemplate"/>
|
||||
<TemplateBinding Property="ItemTemplate"/>
|
||||
</MultiBinding>
|
||||
</ContentPresenter.ContentTemplate>
|
||||
</ContentPresenter>
|
||||
<Border
|
||||
x:Name="DropDownOverlay"
|
||||
Grid.Column="2"
|
||||
@@ -54,19 +62,18 @@
|
||||
HorizontalAlignment="Right"
|
||||
Background="Transparent"
|
||||
IsVisible="False" />
|
||||
|
||||
<PathIcon
|
||||
x:Name="DropDownGlyph"
|
||||
Grid.Column="2"
|
||||
Width="12"
|
||||
Height="12"
|
||||
Margin="0,0,10,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Data="{DynamicResource ComboBoxIcon}"
|
||||
Foreground="{DynamicResource ComboBoxIconDefaultForeground}"
|
||||
IsHitTestVisible="False"
|
||||
UseLayoutRounding="False" />
|
||||
<Panel Grid.Column="2" Width="32" IsHitTestVisible="False">
|
||||
<PathIcon
|
||||
x:Name="DropDownGlyph"
|
||||
Width="12"
|
||||
Height="12"
|
||||
Margin="0,0,10,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Data="{DynamicResource ComboBoxIcon}"
|
||||
Foreground="{DynamicResource ComboBoxIconDefaultForeground}"
|
||||
UseLayoutRounding="False" />
|
||||
</Panel>
|
||||
<Popup
|
||||
Name="{x:Static iri:PartNames.PART_Popup}"
|
||||
Grid.Column="0"
|
||||
@@ -77,7 +84,7 @@
|
||||
PlacementTarget="Background"
|
||||
WindowManagerAddShadowHint="False"
|
||||
IsLightDismissEnabled="True"
|
||||
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
|
||||
<Border
|
||||
Name="PopupBorder"
|
||||
Margin="0 4"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Globalization;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace Ursa.Themes.Semi.Converters;
|
||||
|
||||
public class SelectedItemTemplateConverter: IMultiValueConverter
|
||||
{
|
||||
public static SelectedItemTemplateConverter Instance { get; } = new SelectedItemTemplateConverter();
|
||||
|
||||
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if(values.Count>0 && values[0] is IDataTemplate template1)
|
||||
{
|
||||
return template1;
|
||||
}
|
||||
if(values.Count>1 && values[1] is IDataTemplate template2)
|
||||
{
|
||||
return template2;
|
||||
}
|
||||
return AvaloniaProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user