提交记录新增UI/Controls/Expander/Expander.cs+187 −0看文件
新增UI/Themes/Expander/Expander.xaml+119 −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 | 新增:} | |
| @@ -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> | |
| 文件末尾没有换行 | ||

