feat: move readonly to item.

This commit is contained in:
rabbitism
2024-03-05 17:53:16 +08:00
parent fdc6b2e156
commit 8ac608505b
5 changed files with 25 additions and 71 deletions

View File

@@ -19,13 +19,9 @@
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
</ControlTemplate>
</Setter>
<Style Selector="^[IsReadOnly=True]">
<Setter Property="ItemContainerTheme" Value="{DynamicResource ReadOnlyBreadcrumbItem}"></Setter>
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type u:BreadcrumbItem}" TargetType="u:BreadcrumbItem">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<ControlTemplate TargetType="u:BreadcrumbItem">
<Border Background="Transparent">
@@ -61,6 +57,9 @@
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^[IsReadOnly=False]">
<Setter Property="Cursor" Value="Hand"></Setter>
</Style>
<Style Selector="^:last">
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}" />
@@ -72,7 +71,7 @@
<Style Selector="^ /template/ ContentPresenter#Separator">
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="^:pointerover">
<Style Selector="^[IsReadOnly=False]:pointerover">
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}" />
</Style>
@@ -81,7 +80,7 @@
</Style>
</Style>
</Style>
<Style Selector="^:pointerover">
<Style Selector="^[IsReadOnly=False]:pointerover">
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
<Setter Property="Foreground" Value="{DynamicResource SemiBlue5}" />
</Style>
@@ -90,55 +89,4 @@
</Style>
</Style>
</ControlTheme>
<ControlTheme x:Key="ReadOnlyBreadcrumbItem" TargetType="u:BreadcrumbItem">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<ControlTemplate TargetType="u:BreadcrumbItem">
<Border Background="Transparent">
<StackPanel Orientation="Horizontal">
<ContentPresenter
Name="PART_IconPresenter"
Margin="0,0,4,0"
VerticalAlignment="Center"
Content="{TemplateBinding Icon}"
ContentTemplate="{TemplateBinding IconTemplate}"
Foreground="{DynamicResource SemiColorText2}"
IsVisible="{TemplateBinding Icon,
Converter={x:Static ObjectConverters.IsNotNull}}" />
<ContentPresenter
Name="PART_ContentPresenter"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{DynamicResource SemiColorText2}"
IsVisible="{TemplateBinding Content,
Converter={x:Static ObjectConverters.IsNotNull}}" />
<ContentPresenter
Name="Separator"
Margin="4,0 0 0"
VerticalAlignment="Center"
Content="{TemplateBinding Separator}"
Foreground="{DynamicResource SemiColorText3}">
<ContentPresenter.IsVisible>
<TemplateBinding Converter="{x:Static ObjectConverters.IsNotNull}" Property="Separator" />
</ContentPresenter.IsVisible>
</ContentPresenter>
</StackPanel>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:last">
<Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource SemiColorText0}" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style Selector="^ /template/ ContentPresenter#Separator">
<Setter Property="IsVisible" Value="False" />
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>

View File

@@ -56,15 +56,6 @@ public class Breadcrumb: ItemsControl
get => GetValue(IconTemplateProperty);
set => SetValue(IconTemplateProperty, value);
}
public static readonly StyledProperty<bool> IsReadOnlyProperty = AvaloniaProperty.Register<Breadcrumb, bool>(
nameof(IsReadOnly));
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
static Breadcrumb()
{

View File

@@ -49,11 +49,19 @@ public class BreadcrumbItem: ContentControl
set => SetValue(IconTemplateProperty, value);
}
public static readonly StyledProperty<bool> IsReadOnlyProperty = AvaloniaProperty.Register<BreadcrumbItem, bool>(
nameof(IsReadOnly));
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
var parent = this.FindLogicalAncestorOfType<Breadcrumb>();
if (parent?.IsReadOnly != true)
if (!IsReadOnly)
{
Command?.Execute(null);
}