跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
新增UI/Controls/Expander/Expander.cs+187 −0看文件
@@ -0,0 +1,187 @@
1新增:using System;
2新增:using System.Collections.Generic;
3新增:using System.Diagnostics;
4新增:using System.Linq;
5新增:using System.Text;
6新增:using System.Threading.Tasks;
7新增:using System.Windows;
8新增:using System.Windows.Controls;
9新增:using System.Windows.Input;
10新增:using System.Windows.Media.Animation;
11新增:using UI.Controls.Button;
12新增:using UI.Controls.Input;
13新增:using UI.Controls.SettingPanel;
14新增:
15新增:namespace UI.Controls.Expander
16新增:{
17新增: public class Expander : System.Windows.Controls.Expander
18新增: {
19新增: /// <summary>
20新增: /// 圆角半径
21新增: /// </summary>
22新增: public CornerRadius CornerRadius
23新增: {
24新增: get { return (CornerRadius)GetValue(CornerRadiusProperty); }
25新增: set { SetValue(CornerRadiusProperty, value); }
26新增: }
27新增: public static readonly DependencyProperty CornerRadiusProperty =
28新增: DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(Expander));
29新增:
30新增: public Command ExpanderCommand { get; set; }
31新增: private Border HeaderBorder_;
32新增: private IconButton ExpBtn_;
33新增: // 内容容器高度隐藏容器,用于辅助显示隐藏动画
34新增: private Canvas ContentHeightCanvas_;
35新增: // 内容部分容器边框,用于设置下移动画
36新增: private Border ContentBorder_;
37新增: private StackPanel ContentStackPanel_;
38新增:
39新增:
40新增: private Storyboard storyboard;
41新增: private DoubleAnimation expandTTFDoubleAnimation;
42新增: private DoubleAnimation expandHeightDoubleAnimation;
43新增:
44新增: public Expander()
45新增: {
46新增: DefaultStyleKey = typeof(Expander);
47新增: ExpanderCommand = new Command(new Action<object>(OnExpanderCommand));
48新增: Loaded += Expander_Loaded;
49新增: }
50新增:
51新增: private void Expander_Loaded(object sender, RoutedEventArgs e)
52新增: {
53新增: ContentHeightCanvas_.SetValue(HeightProperty, ContentStackPanel_.ActualHeight);
54新增: ContentStackPanel_.SizeChanged += ContentStackPanel__SizeChanged;
55新增: //OnExpand(false);
56新增: }
57新增:
58新增: private void CreateAnimations()
59新增: {
60新增: storyboard = new Storyboard();
61新增: expandTTFDoubleAnimation = new DoubleAnimation();
62新增: expandTTFDoubleAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
63新增: Storyboard.SetTarget(expandTTFDoubleAnimation, ContentBorder_);
64新增: Storyboard.SetTargetProperty(expandTTFDoubleAnimation, new PropertyPath("(Border.RenderTransform).(TranslateTransform.Y)"));
65新增:
66新增: expandHeightDoubleAnimation = new DoubleAnimation();
67新增: expandHeightDoubleAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
68新增: Storyboard.SetTarget(expandHeightDoubleAnimation, ContentHeightCanvas_);
69新增: Storyboard.SetTargetProperty(expandHeightDoubleAnimation, new PropertyPath("(Canvas.Height)"));
70新增:
71新增:
72新增: storyboard.Children.Add(expandTTFDoubleAnimation);
73新增: storyboard.Children.Add(expandHeightDoubleAnimation);
74新增:
75新增: storyboard.Completed += Storyboard_Completed;
76新增: }
77新增:
78新增: private void Storyboard_Completed(object sender, EventArgs e)
79新增: {
80新增: ContentStackPanel_.SizeChanged -= ContentStackPanel__SizeChanged;
81新增:
82新增: if (IsExpanded)
83新增: {
84新增: ContentStackPanel_.SizeChanged += ContentStackPanel__SizeChanged;
85新增: }
86新增: }
87新增:
88新增: private void ContentStackPanel__SizeChanged(object sender, SizeChangedEventArgs e)
89新增: {
90新增: OnExpand(false);
91新增: }
92新增:
93新增: private void OnExpanderCommand(object obj)
94新增: {
95新增: IsExpanded = !IsExpanded;
96新增: OnExpand();
97新增: }
98新增:
99新增: private void OnExpand(bool isAnimation = true)
100新增: {
101新增: //ContentBorder_.SizeChanged -= ContentBorder__SizeChanged;
102新增: if (IsExpanded)
103新增: {
104新增: expandTTFDoubleAnimation.From = -ContentStackPanel_.ActualHeight;
105新增: expandTTFDoubleAnimation.To = 0;
106新增:
107新增: expandHeightDoubleAnimation.From = 0;
108新增: expandHeightDoubleAnimation.To = ContentStackPanel_.ActualHeight;
109新增: }
110新增: else
111新增: {
112新增: expandTTFDoubleAnimation.From = 0;
113新增: expandTTFDoubleAnimation.To = -ContentStackPanel_.ActualHeight;
114新增:
115新增: expandHeightDoubleAnimation.From = ContentStackPanel_.ActualHeight;
116新增: expandHeightDoubleAnimation.To = 0;
117新增: }
118新增:
119新增: if (!isAnimation)
120新增: {
121新增: expandTTFDoubleAnimation.Duration = new Duration(TimeSpan.Zero);
122新增: expandHeightDoubleAnimation.Duration = new Duration(TimeSpan.Zero);
123新增: }
124新增: else
125新增: {
126新增: expandTTFDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(.3));
127新增: expandHeightDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(.25));
128新增: }
129新增: storyboard.Begin();
130新增: }
131新增:
132新增: public override void OnApplyTemplate()
133新增: {
134新增: base.OnApplyTemplate();
135新增: HeaderBorder_ = GetTemplateChild("HeaderBorder") as Border;
136新增: ExpBtn_ = GetTemplateChild("ExpBtn") as IconButton;
137新增: ContentHeightCanvas_ = GetTemplateChild("ContentHeight") as Canvas;
138新增: ContentBorder_ = GetTemplateChild("Content") as Border;
139新增: ContentStackPanel_ = GetTemplateChild("ContentStackPanel") as StackPanel;
140新增:
141新增: CreateAnimations();
142新增: HandleEvent();
143新增: }
144新增:
145新增: private void HandleEvent()
146新增: {
147新增: if (HeaderBorder_ != null)
148新增: {
149新增: HeaderBorder_.MouseEnter += HeaderBorder__MouseEnter;
150新增: HeaderBorder_.MouseLeave += HeaderBorder__MouseLeave;
151新增: HeaderBorder_.MouseLeftButtonDown += HeaderBorder__MouseLeftButtonDown;
152新增: HeaderBorder_.MouseLeftButtonUp += HeaderBorder__MouseLeftButtonUp;
153新增: }
154新增:
155新增: if(ExpBtn_!= null)
156新增: {
157新增: ExpBtn_.MouseLeftButtonUp += ExpBtn__MouseLeftButtonUp; ;
158新增: }
159新增:
160新增: }
161新增:
162新增: private void ExpBtn__MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
163新增: {
164新增: e.Handled = true;
165新增: }
166新增:
167新增: private void HeaderBorder__MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
168新增: {
169新增: ExpBtn_.RaiseEvent(e);
170新增: }
171新增:
172新增: private void HeaderBorder__MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
173新增: {
174新增: ExpBtn_.RaiseEvent(e);
175新增: }
176新增:
177新增: private void HeaderBorder__MouseLeave(object sender, MouseEventArgs e)
178新增: {
179新增: ExpBtn_.RaiseEvent(e);
180新增: }
181新增:
182新增: private void HeaderBorder__MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
183新增: {
184新增: ExpBtn_.RaiseEvent(e);
185新增: }
186新增: }
187新增:}
新增UI/Themes/Expander/Expander.xaml+119 −0看文件
@@ -0,0 +1,119 @@
1新增:<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2新增: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3新增: xmlns:local="clr-namespace:UI.Controls.Expander"
4新增: xmlns:btn="clr-namespace:UI.Controls.Button"
5新增: xmlns:base="clr-namespace:UI.Controls.Base">
6新增:
7新增:
8新增: <Style TargetType="{x:Type local:Expander}">
9新增: <Setter Property="Background" Value="{DynamicResource ExpanderBgBrush}"/>
10新增: <Setter Property="BorderBrush" Value="{DynamicResource SettingPanelBorderBrush}"/>
11新增: <Setter Property="BorderThickness" Value="1"/>
12新增: <Setter Property="CornerRadius" Value="6"/>
13新增: <Setter Property="Padding" Value="15"/>
14新增: <Setter Property="Template">
15新增: <Setter.Value>
16新增: <ControlTemplate TargetType="{x:Type local:Expander}">
17新增: <Border ClipToBounds="True" Background="Transparent">
18新增: <Grid Background="Transparent">
19新增: <Grid.RowDefinitions>
20新增: <RowDefinition Height="Auto" />
21新增: <RowDefinition x:Name="ContentRow"
22新增: Height="{Binding Height,ElementName=ContentHeight}" />
23新增: </Grid.RowDefinitions>
24新增: <VisualStateManager.VisualStateGroups>
25新增: <VisualStateGroup x:Name="CommonStates">
26新增: <VisualState x:Name="Normal" />
27新增: <VisualState x:Name="MouseOver" />
28新增: <!--<VisualState x:Name="Disabled">
29新增: <Storyboard>
30新增: <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
31新增: Storyboard.TargetProperty="(Panel.Background).
32新增: (GradientBrush.GradientStops)[1].(GradientStop.Color)">
33新增: <EasingColorKeyFrame KeyTime="0"
34新增: Value="{StaticResource DisabledControlDarkColor}" />
35新增: </ColorAnimationUsingKeyFrames>
36新增: <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
37新增: Storyboard.TargetProperty="(Border.BorderBrush).
38新增: (GradientBrush.GradientStops)[1].(GradientStop.Color)">
39新增: <EasingColorKeyFrame KeyTime="0"
40新增: Value="{StaticResource DisabledBorderLightColor}" />
41新增: </ColorAnimationUsingKeyFrames>
42新增: </Storyboard>
43新增: </VisualState>-->
44新增: </VisualStateGroup>
45新增: </VisualStateManager.VisualStateGroups>
46新增: <Canvas x:Name="ContentHeight" Visibility="Collapsed" Height="0"/>
47新增:
48新增: <Border x:Name="HeaderBorder"
49新增: Grid.Row="0"
50新增: Padding="{TemplateBinding Padding}"
51新增: Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" Panel.ZIndex="2">
52新增:
53新增: <Grid>
54新增: <Grid.ColumnDefinitions>
55新增: <ColumnDefinition Width="*" />
56新增: <ColumnDefinition Width="40" />
57新增:
58新增: </Grid.ColumnDefinitions>
59新增:
60新增: <ContentPresenter
61新增: Margin="4"
62新增: ContentSource="Header"
63新增: RecognizesAccessKey="True" TextElement.FontSize="14" VerticalAlignment="Center"/>
64新增: <btn:IconButton x:Name="ExpBtn" Grid.Column="1" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Expander}}, Path=ExpanderCommand}">
65新增: <base:Icon x:Name="Icon" IconType="ChevronDownMed" FontSize="12" RenderTransformOrigin=".5,.5">
66新增: <base:Icon.RenderTransform>
67新增: <RotateTransform Angle="0"/>
68新增: </base:Icon.RenderTransform>
69新增: </base:Icon>
70新增: </btn:IconButton>
71新增: </Grid>
72新增: </Border>
73新增: <Border x:Name="Content"
74新增: Grid.Row="1"
75新增: BorderThickness="1,0,1,1"
76新增: BorderBrush="{TemplateBinding BorderBrush}"
77新增: Background="{DynamicResource ExpanderContentBgBrush}"
78新增: CornerRadius="0,0,6,6">
79新增: <Border.RenderTransform>
80新增: <TranslateTransform X="0" Y="0"/>
81新增: </Border.RenderTransform>
82新增: <StackPanel x:Name="ContentStackPanel">
83新增: <ContentPresenter />
84新增: </StackPanel>
85新增: </Border>
86新增: </Grid>
87新增: </Border>
88新增: <ControlTemplate.Triggers>
89新增: <Trigger Property="IsExpanded"
90新增: Value="True">
91新增: <Setter Property="CornerRadius" Value="6,6,0,0"/>
92新增: <!--<Setter TargetName="ContentRow"
93新增: Property="Height"
94新增: Value="{Binding Height, ElementName=Content}" />-->
95新增: </Trigger>
96新增: <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsExpanded}" Value="True">
97新增: <DataTrigger.EnterActions>
98新增: <BeginStoryboard>
99新增: <Storyboard>
100新增: <DoubleAnimation Storyboard.TargetProperty="(base:Icon.RenderTransform).(RotateTransform.Angle)"
101新增: Storyboard.TargetName="Icon" Duration="00:00:0.2" To="180"/>
102新增: </Storyboard>
103新增: </BeginStoryboard>
104新增: </DataTrigger.EnterActions>
105新增: <DataTrigger.ExitActions>
106新增: <BeginStoryboard>
107新增: <Storyboard>
108新增: <DoubleAnimation Storyboard.TargetProperty="(base:Icon.RenderTransform).(RotateTransform.Angle)"
109新增: Storyboard.TargetName="Icon" Duration="00:00:0.2" To="0"/>
110新增: </Storyboard>
111新增: </BeginStoryboard>
112新增: </DataTrigger.ExitActions>
113新增: </DataTrigger>
114新增: </ControlTemplate.Triggers>
115新增: </ControlTemplate>
116新增: </Setter.Value>
117新增: </Setter>
118新增: </Style>
119新增:</ResourceDictionary>
文件末尾没有换行