mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Implement CardGroup control
This commit is contained in:
parent
61c14109bc
commit
08687d63cb
5 changed files with 115 additions and 0 deletions
|
|
@ -37,6 +37,27 @@
|
|||
<Setter Property="Padding" Value="38,0,26,0" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Binding="{Binding GroupPosition, 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">
|
||||
<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">
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="CornerRadius" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0 1 0 0" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
|
|
|
|||
|
|
@ -12,10 +12,27 @@ 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); }
|
||||
|
|
|
|||
31
Flow.Launcher/Resources/Controls/CardGroup.xaml
Normal file
31
Flow.Launcher/Resources/Controls/CardGroup.xaml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<UserControl x:Class="Flow.Launcher.Resources.Controls.CardGroup"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance cc:CardGroup}"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<UserControl.Resources>
|
||||
<Style TargetType="cc:Card" x:Key="FirstStyle">
|
||||
<Setter Property="GroupPosition" Value="First" />
|
||||
</Style>
|
||||
<Style TargetType="cc:Card" x:Key="MiddleStyle">
|
||||
<Setter Property="GroupPosition" Value="Middle" />
|
||||
</Style>
|
||||
<Style TargetType="cc:Card" x:Key="LastStyle">
|
||||
<Setter Property="GroupPosition" Value="Last" />
|
||||
</Style>
|
||||
|
||||
<cc:CardGroupCardStyleSelector
|
||||
x:Key="CardStyleSelector"
|
||||
FirstStyle="{StaticResource FirstStyle}"
|
||||
MiddleStyle="{StaticResource MiddleStyle}"
|
||||
LastStyle="{StaticResource LastStyle}" />
|
||||
</UserControl.Resources>
|
||||
<Border Background="{DynamicResource Color00B}" BorderBrush="{DynamicResource Color03B}" BorderThickness="1"
|
||||
CornerRadius="5">
|
||||
<ItemsControl ItemsSource="{Binding Content}" ItemContainerStyleSelector="{StaticResource CardStyleSelector}" />
|
||||
</Border>
|
||||
</UserControl>
|
||||
25
Flow.Launcher/Resources/Controls/CardGroup.xaml.cs
Normal file
25
Flow.Launcher/Resources/Controls/CardGroup.xaml.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Flow.Launcher.Resources.Controls;
|
||||
|
||||
public partial class CardGroup : UserControl
|
||||
{
|
||||
public new ObservableCollection<Card> Content
|
||||
{
|
||||
get { return (ObservableCollection<Card>)GetValue(ContentProperty); }
|
||||
set { SetValue(ContentProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ContentProperty =
|
||||
DependencyProperty.Register(nameof(Content), typeof(ObservableCollection<Card>), typeof(CardGroup));
|
||||
|
||||
public CardGroup()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
Content = new ObservableCollection<Card>();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Flow.Launcher.Resources.Controls;
|
||||
|
||||
public class CardGroupCardStyleSelector : StyleSelector
|
||||
{
|
||||
public Style FirstStyle { get; set; }
|
||||
public Style MiddleStyle { get; set; }
|
||||
public Style LastStyle { get; set; }
|
||||
|
||||
public override Style SelectStyle(object item, DependencyObject container)
|
||||
{
|
||||
var itemsControl = ItemsControl.ItemsControlFromItemContainer(container);
|
||||
var index = itemsControl.ItemContainerGenerator.IndexFromContainer(container);
|
||||
|
||||
if (index == 0) return FirstStyle;
|
||||
if (index == itemsControl.Items.Count - 1) return LastStyle;
|
||||
return MiddleStyle;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue