洛阳做网站公司在哪,近期国内新闻,北京移动端网站建设,国外二级域名免费申请1#xff0c;创建翻转面板的资源字典#xff1a;FlippPanel.xaml。
无外观控件同样必须给样式指定类型#xff08; ControlTemplate TargetTypess:FlipPanel#xff09;#xff0c;相关详情参考#xff1a;WPF之创建无外观控件-CSDN博客#xff09…1创建翻转面板的资源字典FlippPanel.xaml。
无外观控件同样必须给样式指定类型 ControlTemplate TargetTypess:FlipPanel相关详情参考WPF之创建无外观控件-CSDN博客。
ResourceDictionary xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:ssclr-namespace:无外观控件xmlns:localclr-namespace:无外观控件.ThemesStyle TargetTypess:FlipPanelSetter PropertyTemplateSetter.ValueControlTemplate TargetTypess:FlipPanelGridGrid.RowDefinitionsRowDefinition Heightauto/RowDefinitionRowDefinition Heightauto/RowDefinition/Grid.RowDefinitions!--1为给模板添加VisualStateManager元素模板必须使用布局面板。布局面板包含控件的两个可视化对象和VisualStateManager元素该元素不可见--VisualStateManager.VisualStateGroupsVisualStateGroup NameViewStatesVisualStateGroup.Transitions!--两个可视对象切换时间以及伴随的ToggleButton切换动画--VisualTransition ToNormal GeneratedDuration00:00:01Storyboard DoubleAnimation To0 Storyboard.TargetNamePART_Rota Storyboard.TargetPropertyAngle /DoubleAnimation/Storyboard/VisualTransitionVisualTransition ToFlipped GeneratedDuration00:00:2Storyboard DoubleAnimation To180 Storyboard.TargetNamePART_Rota Storyboard.TargetPropertyAngle /DoubleAnimation/Storyboard/VisualTransition/VisualStateGroup.TransitionsVisualState NameNormalStoryboard DoubleAnimation To0 Storyboard.TargetNamefront Storyboard.TargetPropertyOpacity Duration00:00:00/DoubleAnimation!--ToggleButton旋转动画不能省否则动画异常--DoubleAnimation To0 Storyboard.TargetNamePART_Rota Storyboard.TargetPropertyAngle/DoubleAnimation/Storyboard/VisualStateVisualState NameFlippedStoryboard DoubleAnimation To0 Storyboard.TargetNameback Storyboard.TargetPropertyOpacity Duration00:00:00/DoubleAnimation!--ToggleButton旋转动画不能省否则动画异常--DoubleAnimation To180 Storyboard.TargetNamePART_Rota Storyboard.TargetPropertyAngle Duration00:00:00 /DoubleAnimation/Storyboard/VisualState/VisualStateGroup/VisualStateManager.VisualStateGroupsBorder x:Namefront BorderBrush{TemplateBinding BorderBrush} CornerRadius{TemplateBinding CornerRadius} BorderThickness{TemplateBinding BorderThickness} Background{TemplateBinding Background}ContentPresenter Content{TemplateBinding FrontContent}/ContentPresenter/BorderBorder x:Nameback BorderBrush{TemplateBinding BorderBrush} CornerRadius{TemplateBinding CornerRadius} BorderThickness{TemplateBinding BorderThickness} Background{TemplateBinding Background}ContentPresenter Content{TemplateBinding BackContent}/ContentPresenter/BorderToggleButton Grid.Row1 Height40 NameFlipButton RenderTransformOrigin0.5,0.5ToggleButton.RenderTransformRotateTransform x:NamePART_Rota /RotateTransform/ToggleButton.RenderTransformToggleButton.TemplateControlTemplate TargetTypeToggleButtonToggleButton Grid.Column1 Grid.Row1 NameFlipButtonToggleButton.TemplateControlTemplate TargetTypeToggleButtonRectangle Rectangle.FillDrawingBrush StretchNoneDrawingBrush.DrawingGeometryDrawing BrushWhiteGeometryDrawing.PenPen BrushBlack Thickness2/Pen/GeometryDrawing.PenGeometryDrawing.GeometryGeometryGroupEllipseGeometry RadiusX15 RadiusY15/EllipseGeometryCombinedGeometry GeometryCombineModeIntersectCombinedGeometry.Geometry1EllipseGeometry RadiusX7.5 RadiusY7.5/EllipseGeometry/CombinedGeometry.Geometry1CombinedGeometry.Geometry2PathGeometry FiguresM-7.5,0 L0,-7.5 L7.5,-7.5 L0,0 L7.5,7.5 L0,7.5 Z/PathGeometry/CombinedGeometry.Geometry2/CombinedGeometry/GeometryGroup/GeometryDrawing.Geometry/GeometryDrawing/DrawingBrush.Drawing/DrawingBrush/Rectangle.Fill/Rectangle/ControlTemplate/ToggleButton.Template/ToggleButton/ControlTemplate/ToggleButton.Template/ToggleButton/Grid/ControlTemplate/Setter.Value/Setter/Style
/ResourceDictionary
VisualStateManager只能在布局面板下进行状态管理。
2在generic.xaml中添加资源字典FlipPanel.xaml.
ResourceDictionaryxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlResourceDictionary.MergedDictionariesResourceDictionary Source无外观控件;component/Themes/colorpicker.xaml/ResourceDictionaryResourceDictionary Source无外观控件;component/Themes/FlipPanel.xaml/ResourceDictionary/ResourceDictionary.MergedDictionaries
/ResourceDictionary
3,编写代码 [TemplatePart(Name FlipButton, Type typeof(ToggleButton))]//该特性只是进行提示无其他意义可舍去[TemplateVisualState(GroupName Normal, Name ViewStates)]//该特性提示存在可视化切换无其他实际意义可舍去[TemplateVisualState(GroupName Flipped, Name ViewStates)]public class FlipPanel : Control{public static readonly DependencyProperty CornerRadiusProperty;public static readonly DependencyProperty FrontContentProperty;public static readonly DependencyProperty BackContentProperty;public static readonly DependencyProperty IsFlippedProperty;static FlipPanel(){DefaultStyleKeyProperty.OverrideMetadata(typeof(FlipPanel), new FrameworkPropertyMetadata(typeof(FlipPanel)));CornerRadiusProperty DependencyProperty.Register(CornerRadius, typeof(CornerRadius), typeof(FlipPanel));FrontContentProperty DependencyProperty.Register(FrontContent, typeof(object), typeof(FlipPanel));BackContentProperty DependencyProperty.Register(BackContent, typeof(object), typeof(FlipPanel));IsFlippedProperty DependencyProperty.Register(IsFlipped, typeof(bool), typeof(FlipPanel));}/// summary/// 设置控件边框倒角/// /summarypublic CornerRadius CornerRadius{get{return (CornerRadius)this.GetValue(CornerRadiusProperty);}set{this.SetValue(CornerRadiusProperty, value);}}/// summary/// 前置内容/// /summarypublic object FrontContent{get{return this.GetValue(FrontContentProperty);}set{this.SetValue(FrontContentProperty, value);}}/// summary/// 后置内容/// /summarypublic object BackContent{get{return GetValue(BackContentProperty);}set{this.SetValue(BackContentProperty, value);}}/// summary/// 是否翻转/// /summarypublic bool IsFlipped{get{return (bool)GetValue(IsFlippedProperty);}set{SetValue(IsFlippedProperty, value);ChangeVisualState(true);}}public override void OnApplyTemplate(){ToggleButton btn GetTemplateChild(FlipButton) as ToggleButton;btn.Click Btn_Click;ChangeVisualState(false);base.OnApplyTemplate();}private void Btn_Click(object sender, RoutedEventArgs e){IsFlipped !IsFlipped;}void ChangeVisualState(bool useTransition){if (IsFlipped){VisualStateManager.GoToState(this, Flipped, useTransition);}else{VisualStateManager.GoToState(this, Normal, useTransition);}}}
4在UI上添加控件
local:FlipPanel Grid.Row1 IsFlippedTruelocal:FlipPanel.FrontContentStackPanelButton Content前1/ButtonButton Content前2/ButtonButton Content前3/ButtonButton Content前3/ButtonButton Content前4/Button/StackPanel/local:FlipPanel.FrontContentlocal:FlipPanel.BackContentStackPanelButton Content后1/Button/StackPanel/local:FlipPanel.BackContent/local:FlipPanel
5效果 6Demo 链接
https://download.csdn.net/download/lingxiao16888/89253829?spm1001.2014.3001.5501