Replace Card.GroupPosition with CardGroup.Position attached property

This commit is contained in:
Yusyuriv 2024-05-02 20:48:24 +06:00
parent fb6b1bb518
commit aaef48cd16
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
4 changed files with 29 additions and 22 deletions

View file

@ -38,21 +38,21 @@
<Setter Property="Background" Value="Transparent" />
</DataTrigger>
<DataTrigger Binding="{Binding GroupPosition, RelativeSource={RelativeSource AncestorType=local:Card}}" Value="First">
<DataTrigger Binding="{Binding (local:CardGroup.Position), RelativeSource={RelativeSource AncestorType=local:Card}}" Value="First">
<Setter Property="Margin" Value="0" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</DataTrigger>
<DataTrigger Binding="{Binding GroupPosition, RelativeSource={RelativeSource AncestorType=local:Card}}" Value="Middle">
<DataTrigger Binding="{Binding (local:CardGroup.Position), RelativeSource={RelativeSource AncestorType=local:Card}}" Value="Middle">
<Setter Property="Margin" Value="0" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0 1 0 0" />
</DataTrigger>
<DataTrigger Binding="{Binding GroupPosition, RelativeSource={RelativeSource AncestorType=local:Card}}" Value="Last">
<DataTrigger Binding="{Binding (local:CardGroup.Position), RelativeSource={RelativeSource AncestorType=local:Card}}" Value="Last">
<Setter Property="Margin" Value="0" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Background" Value="Transparent" />

View file

@ -12,27 +12,11 @@ namespace Flow.Launcher.Resources.Controls
InsideFit
}
public enum CardGroupPosition
{
NotInGroup,
First,
Middle,
Last
}
public Card()
{
InitializeComponent();
}
public CardGroupPosition GroupPosition
{
get { return (CardGroupPosition)GetValue(GroupPositionProperty); }
set { SetValue(GroupPositionProperty, value); }
}
public static readonly DependencyProperty GroupPositionProperty =
DependencyProperty.Register(nameof(GroupPosition), typeof(CardGroupPosition), typeof(Card), new PropertyMetadata(CardGroupPosition.NotInGroup));
public string Title
{
get { return (string)GetValue(TitleProperty); }

View file

@ -9,13 +9,13 @@
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style TargetType="cc:Card" x:Key="FirstStyle">
<Setter Property="GroupPosition" Value="First" />
<Setter Property="cc:CardGroup.Position" Value="First" />
</Style>
<Style TargetType="cc:Card" x:Key="MiddleStyle">
<Setter Property="GroupPosition" Value="Middle" />
<Setter Property="cc:CardGroup.Position" Value="Middle" />
</Style>
<Style TargetType="cc:Card" x:Key="LastStyle">
<Setter Property="GroupPosition" Value="Last" />
<Setter Property="cc:CardGroup.Position" Value="Last" />
</Style>
<cc:CardGroupCardStyleSelector

View file

@ -7,6 +7,14 @@ namespace Flow.Launcher.Resources.Controls;
public partial class CardGroup : UserControl
{
public enum CardGroupPosition
{
NotInGroup,
First,
Middle,
Last
}
public new ObservableCollection<Card> Content
{
get { return (ObservableCollection<Card>)GetValue(ContentProperty); }
@ -16,6 +24,21 @@ public partial class CardGroup : UserControl
public static new readonly DependencyProperty ContentProperty =
DependencyProperty.Register(nameof(Content), typeof(ObservableCollection<Card>), typeof(CardGroup));
public static readonly DependencyProperty PositionProperty = DependencyProperty.RegisterAttached(
"Position", typeof(CardGroupPosition), typeof(CardGroup),
new FrameworkPropertyMetadata(CardGroupPosition.NotInGroup, FrameworkPropertyMetadataOptions.AffectsRender)
);
public static void SetPosition(UIElement element, CardGroupPosition value)
{
element.SetValue(PositionProperty, value);
}
public static CardGroupPosition GetPosition(UIElement element)
{
return (CardGroupPosition)element.GetValue(PositionProperty);
}
public CardGroup()
{
InitializeComponent();