Files
GeekDesk/Control/UserControls/PannelCard/LeftCardControl.xaml
2021-07-19 17:30:34 +08:00

151 lines
8.5 KiB
XML

<UserControl x:Class="GeekDesk.Control.UserControls.PannelCard.LeftCardControl"
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:local="clr-namespace:GeekDesk.Control.UserControls.PannelCard"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:cvt="clr-namespace:GeekDesk.Converts"
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<!--左侧栏样式动画-->
<Style x:Key="MenuStyle" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItemBaseStyle}">
<Setter Property="FontSize" Value="15"/>
<Setter Property="Margin" Value="0,0,0,1"/>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Opacity="0"/>
</Setter.Value>
</Setter>
<EventSetter Event="MouseLeftButtonDown" Handler="MenuClick"/>
<EventSetter Event="MouseRightButtonDown" Handler="MenuClick"/>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="False"/>
<Condition Property="IsSelected" Value="False"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="15" Duration="0:0:0.5" Storyboard.TargetProperty="FontSize"/>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard>
<Storyboard Timeline.DesiredFrameRate="60">
<DoubleAnimation To="18" Duration="0:0:0.001" Storyboard.TargetProperty="FontSize"/>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
</MultiTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFE4DBDB"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#FFECECEC"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
<cvt:MenuWidthConvert x:Key="MenuWidthConvert"/>
<cvt:OpcityConvert x:Key="OpcityConvert"/>
</UserControl.Resources>
<!--左侧栏-->
<hc:Card x:Name="MyCard"
BorderThickness="1"
Effect="{DynamicResource EffectShadow2}"
Margin="5,0,0,5"
>
<hc:Card.Background>
<SolidColorBrush Color="#FFFFFFFF" hc:GeometryEffect.GeometryEffect="20" Opacity="{Binding AppConfig.CardOpacity, Mode=TwoWay, Converter={StaticResource OpcityConvert}}">
</SolidColorBrush>
</hc:Card.Background>
<hc:Card.BorderBrush>
<SolidColorBrush Color="#FFFFFFFF" Opacity="0"/>
</hc:Card.BorderBrush>
<hc:Card.ContextMenu>
<ContextMenu Width="200">
<MenuItem Header="新建菜单" Click="CreateMenu"/>
</ContextMenu>
</hc:Card.ContextMenu>
<WrapPanel Orientation="Horizontal">
<ListBox x:Name="MenuListBox"
ItemsSource="{Binding MenuList}"
Tag="{Binding AppConfig.MenuCardWidth}"
BorderThickness="0" Foreground="{x:Null}"
SelectedIndex="{Binding AppConfig.SelectedMenuIndex}"
VirtualizingPanel.VirtualizationMode="Recycling"
SelectionChanged="menus_SelectionChanged"
>
<ListBox.Resources>
<ContextMenu x:Key="menuDialog" Width="200">
<MenuItem Header="新建菜单" Click="CreateMenu"/>
<MenuItem Header="重命名" Click="RenameMenu" Tag="{Binding}"/>
<MenuItem Header="修改图标" Click="EditMenuGeometry" Tag="{Binding}"/>
<MenuItem Header="删除" Click="DeleteMenu" Tag="{Binding}"/>
</ContextMenu>
</ListBox.Resources>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource MenuStyle}">
<Setter Property="ContextMenu" Value="{StaticResource menuDialog}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Background>
<SolidColorBrush Color="AliceBlue" Opacity="0"/>
</ListBox.Background>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<DraggAnimatedPanel:DraggAnimatedPanel ItemsHeight="30" ItemsWidth="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBox},AncestorLevel=1},Path=Tag, Mode=TwoWay, Converter={StaticResource MenuWidthConvert}}" HorizontalAlignment="Center" VerticalAlignment="Top" SwapCommand="{Binding SwapCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel MouseLeftButtonDown="MenuClick" MouseRightButtonDown="MenuClick" Tag="{Binding}">
<StackPanel.Background>
<SolidColorBrush Color="AliceBlue" Opacity="0.01"/>
</StackPanel.Background>
<hc:TextBox Text="{Binding Path=MenuName, Mode=TwoWay}"
HorizontalAlignment="Left"
Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBox},AncestorLevel=1},Path=Tag, Mode=TwoWay, Converter={StaticResource MenuWidthConvert}}"
FontSize="15"
TextAlignment="Left"
LostFocus="LostFocusOrEnterDown"
KeyDown="LostFocusOrEnterDown"
Tag="{Binding}"
IsVisibleChanged="MenuEditWhenVisibilityChanged"
Visibility="{Binding MenuEdit}"/>
<StackPanel Orientation="Horizontal">
<Button Background="Transparent"
BorderThickness="0"
hc:IconElement.Geometry="{Binding MenuGeometry}"
hc:IconElement.Height="18"
hc:IconElement.Width="18"
IsEnabled="False"
Opacity="1"
Foreground="{Binding GeometryColor}"
/>
<TextBlock Text="{Binding MenuName}"
HorizontalAlignment="Center"
TextAlignment="Center"
VerticalAlignment="Center"
IsVisibleChanged="MenuWhenVisibilityChanged"
Visibility="{Binding NotMenuEdit}"
/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</hc:Card>
</UserControl>