南昌有限公司 网站,企业内部网站建设费用,张掖哪家公司做网站,移动开发主要学什么WPF开发者QQ群#xff1a; 340500857  | 微信群 - 进入公众号主页 加入组织欢迎转发、分享、点赞、在看#xff0c;谢谢~。  01—效果预览效果预览#xff08;更多效果请下载源码体验#xff09;#xff1a;02—代码如下一、CycleLoading.cs 代码如下using System.Win…  WPF开发者QQ群 340500857  | 微信群 - 进入公众号主页 加入组织欢迎转发、分享、点赞、在看谢谢~。  01—效果预览效果预览更多效果请下载源码体验02—代码如下一、CycleLoading.cs 代码如下using System.Windows;
using System.Windows.Controls;namespace WPFDevelopers.Controls
{public class CycleLoading : ContentControl{static CycleLoading(){DefaultStyleKeyProperty.OverrideMetadata(typeof(CycleLoading), new FrameworkPropertyMetadata(typeof(CycleLoading)));}public override void OnApplyTemplate(){base.OnApplyTemplate();}public double MaxValue{get { return (double)GetValue(MaxValueProperty); }set { SetValue(MaxValueProperty, value); }}// Using a DependencyProperty as the backing store for MaxValue.  This enables animation, styling, binding, etc...public static readonly DependencyProperty MaxValueProperty DependencyProperty.Register(MaxValue, typeof(double), typeof(CycleLoading), new PropertyMetadata(100d));public double Value{get { return (double)GetValue(ValueProperty); }set { SetValue(ValueProperty, value); }}// Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...public static readonly DependencyProperty ValueProperty DependencyProperty.Register(Value, typeof(double), typeof(CycleLoading), new PropertyMetadata(0d, OnValuePropertyChangedCallBack));internal string ValueDescription{get { return (string)GetValue(ValueDescriptionProperty); }set { SetValue(ValueDescriptionProperty, value); }}// Using a DependencyProperty as the backing store for ValueDescription.  This enables animation, styling, binding, etc...internal static readonly DependencyProperty ValueDescriptionProperty DependencyProperty.Register(ValueDescription, typeof(string), typeof(CycleLoading), new PropertyMetadata(default(string)));private static void OnValuePropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e){if (!(d is CycleLoading loading))return;if (!double.TryParse(e.NewValue?.ToString(), out double value))return;if (value  loading.MaxValue){value  loading.MaxValue;if (loading.IsStart)loading.IsStart  false;}else{if (!loading.IsStart)loading.IsStart  true;}double dValue  value / loading.MaxValue;loading.ValueDescription  dValue.ToString(P0);}public bool IsStart{get { return (bool)GetValue(IsStartProperty); }set { SetValue(IsStartProperty, value); }}// Using a DependencyProperty as the backing store for IsStart.  This enables animation, styling, binding, etc...public static readonly DependencyProperty IsStartProperty DependencyProperty.Register(IsStart, typeof(bool), typeof(CycleLoading), new PropertyMetadata(true));public string LoadTitle{get { return (string)GetValue(LoadTitleProperty); }set { SetValue(LoadTitleProperty, value); }}// Using a DependencyProperty as the backing store for LoadTitle.  This enables animation, styling, binding, etc...public static readonly DependencyProperty LoadTitleProperty DependencyProperty.Register(LoadTitle, typeof(string), typeof(CycleLoading), new PropertyMetadata(default(string)));}
}二、CycleLoading.xaml 代码如下 Style TargetType{x:Type controls:CycleLoading} BasedOn{StaticResource ControlBasicStyle}Setter PropertyForeground ValueWhite/Setter PropertyFontSize Value30/Setter PropertyHorizontalContentAlignment ValueCenter/Setter PropertyVerticalContentAlignment ValueCenter/Setter PropertyTemplateSetter.ValueControlTemplate TargetType{x:Type controls:CycleLoading}ControlTemplate.ResourcesStoryboard x:KeyStoryboard_LoadRunning RepeatBehaviorForever SpeedRatio2DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 Storyboard.TargetNamePart_Cycle_Rotate Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 Storyboard.TargetNamePart_Cycle_Rotate1 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) //Storyboard/ControlTemplate.ResourcesGridViewboxGrid Width400 Height400Grid x:NamePart_Cycle_Rotate1 RenderTransformOrigin0.5,0.5Grid.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Grid.RenderTransformEllipse Margin0,50,0,50 Ellipse.FillLinearGradientBrush GradientStop ColorWhite Offset0 /GradientStop ColorWhite Offset1 //LinearGradientBrush/Ellipse.FillEllipse.EffectBlurEffect Radius40//Ellipse.Effect/EllipseEllipse Margin50,0,50,0 Ellipse.FillLinearGradientBrush StartPoint0,0 EndPoint0,1GradientStop ColorWhite Offset0.4 /GradientStop ColorWhite Offset1 //LinearGradientBrush/Ellipse.FillEllipse.EffectBlurEffect Radius40//Ellipse.Effect/Ellipse/GridGrid x:NamePart_Cycle_Rotate RenderTransformOrigin0.5,0.5Grid.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Grid.RenderTransformEllipse Margin0,50,0,50 Ellipse.FillLinearGradientBrush GradientStop Color#d495f1 Offset0 /GradientStop Color#87d3f7 Offset1 //LinearGradientBrush/Ellipse.FillEllipse.EffectBlurEffect Radius15//Ellipse.Effect/EllipseEllipse Margin50,0,50,0 Ellipse.FillLinearGradientBrush StartPoint0,0 EndPoint0,1GradientStop Color#f173ac Offset0 /GradientStop Color#33a3dc Offset1 //LinearGradientBrush/Ellipse.FillEllipse.EffectBlurEffect Radius15//Ellipse.Effect/Ellipse/GridEllipse Margin33 FillBlack Ellipse.EffectDropShadowEffect BlurRadius20 ShadowDepth0 ColorWhite//Ellipse.Effect/Ellipse/Grid/ViewboxGrid HorizontalAlignment{TemplateBinding HorizontalContentAlignment} VerticalAlignment{TemplateBinding VerticalContentAlignment}Grid.RowDefinitionsRowDefinition HeightAuto/RowDefinition HeightAuto/RowDefinition HeightAuto//Grid.RowDefinitionsTextBlock Grid.Row0 HorizontalAlignmentCenter VerticalAlignmentCenter FontSize20 Text{TemplateBinding LoadTitle}/ContentPresenter Grid.Row1 HorizontalAlignmentCenter VerticalAlignmentCenter Content{TemplateBinding Content} ContentTemplate{TemplateBinding ContentTemplate}ContentTemplateSelector{TemplateBinding ContentTemplateSelector}ContentStringFormat{TemplateBinding ContentStringFormat}/TextBlock Grid.Row2 HorizontalAlignmentCenter VerticalAlignmentCenter FontSize15Text{TemplateBinding ValueDescription}//Grid/GridControlTemplate.TriggersTrigger PropertyIsStart ValueTrueTrigger.EnterActionsBeginStoryboard Storyboard{StaticResource Storyboard_LoadRunning} x:NameStoryboard_LoadRunning//Trigger.EnterActionsTrigger.ExitActionsStopStoryboard BeginStoryboardNameStoryboard_LoadRunning//Trigger.ExitActions/Trigger/ControlTemplate.Triggers/ControlTemplate/Setter.Value/Setter
/Style
三、RollLoading 代码如下 using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;namespace WPFDevelopers.Controls
{public class RollLoading : ContentControl{static RollLoading(){DefaultStyleKeyProperty.OverrideMetadata(typeof(RollLoading), new FrameworkPropertyMetadata(typeof(RollLoading)));}public override void OnApplyTemplate(){base.OnApplyTemplate();}public Color ForegroundColor{get { return (Color)GetValue(ForegroundColorProperty); }set { SetValue(ForegroundColorProperty, value); }}// Using a DependencyProperty as the backing store for ForegroundColor.  This enables animation, styling, binding, etc...public static readonly DependencyProperty ForegroundColorProperty DependencyProperty.Register(ForegroundColor, typeof(Color), typeof(RollLoading), new PropertyMetadata(Colors.Red));public bool IsStart{get { return (bool)GetValue(IsStartProperty); }set { SetValue(IsStartProperty, value); }}// Using a DependencyProperty as the backing store for IsStart.  This enables animation, styling, binding, etc...public static readonly DependencyProperty IsStartProperty DependencyProperty.Register(IsStart, typeof(bool), typeof(RollLoading), new PropertyMetadata(true));}
}四、RollLoading.xaml 代码如下 Style TargetType{x:Type controls:RollLoading} BasedOn{StaticResource ControlBasicStyle}Setter PropertyForegroundColor Value{StaticResource DangerColor}/Setter PropertyTemplate Setter.ValueControlTemplate TargetType{x:Type controls:RollLoading}ControlTemplate.ResourcesStoryboard x:KeyRollKey  RepeatBehaviorForever DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio2 Storyboard.TargetNamePART_Border1 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio4 Storyboard.TargetNamePART_Border2 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio6 Storyboard.TargetNamePART_Border3 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio8 Storyboard.TargetNamePART_Border4 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio10 Storyboard.TargetNamePART_Border5 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio12 Storyboard.TargetNamePART_Border6 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio14 Storyboard.TargetNamePART_Border7 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /DoubleAnimation Duration0:0:5 BeginTime0 From0 To360 RepeatBehaviorForever SpeedRatio16 Storyboard.TargetNamePART_Border8 Storyboard.TargetProperty(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle) /ColorAnimationUsingKeyFrames Duration0:0:5 Storyboard.TargetPropertyForegroundColor RepeatBehaviorForeverEasingColorKeyFrame KeyTime0:0:0 ValueRed EasingFunction{StaticResource PowerEaseInOut}/EasingColorKeyFrame KeyTime0:0:1 ValueBlue EasingFunction{StaticResource PowerEaseInOut}/EasingColorKeyFrame KeyTime0:0:2 ValueYellow EasingFunction{StaticResource PowerEaseInOut}/EasingColorKeyFrame KeyTime0:0:3 ValueGreen EasingFunction{StaticResource PowerEaseInOut}/EasingColorKeyFrame KeyTime0:0:4 ValueAqua EasingFunction{StaticResource PowerEaseInOut}/EasingColorKeyFrame KeyTime0:0:5 ValueRed EasingFunction{StaticResource PowerEaseInOut}//ColorAnimationUsingKeyFrames/Storyboard/ControlTemplate.ResourcesGridGrid.RowDefinitionsRowDefinition/RowDefinition HeightAuto//Grid.RowDefinitionsViewboxGridBorder x:NamePART_Border1 Width160 Height160  BorderThickness0,5,0,0  CornerRadius80 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border2 Width140 Height140  BorderThickness0,5,0,0  CornerRadius70 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border3 Width120 Height120  BorderThickness0,5,0,0  CornerRadius60 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border4 Width100 Height100  BorderThickness0,5,0,0  CornerRadius50 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border5 Width80 Height80  BorderThickness0,5,0,0  CornerRadius40 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border6 Width60 Height60  BorderThickness0,5,0,0  CornerRadius30 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border7 Width40 Height40  BorderThickness0,5,0,0  CornerRadius20 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/BorderBorder x:NamePART_Border8 Width20 Height20  BorderThickness0,5,0,0  CornerRadius10 RenderTransformOrigin0.5,0.5Border.BorderBrushLinearGradientBrush StartPoint0,0 EndPoint1,1LinearGradientBrush.GradientStopsGradientStop Color{Binding RelativeSource{RelativeSource ModeTemplatedParent}, PathForegroundColor} Offset0.5/GradientStop ColorTransparent Offset0.5//LinearGradientBrush.GradientStops/LinearGradientBrush/Border.BorderBrushBorder.RenderTransformTransformGroupScaleTransform/SkewTransform/RotateTransform/TranslateTransform//TransformGroup/Border.RenderTransform/Border/Grid/ViewboxContentPresenter Grid.Row1 HorizontalAlignment{TemplateBinding HorizontalContentAlignment} VerticalAlignment{TemplateBinding VerticalContentAlignment}//GridControlTemplate.TriggersTrigger PropertyIsStart ValueTrueTrigger.EnterActionsBeginStoryboard x:NameRoll_Storyboard Storyboard{StaticResource RollKey}//Trigger.EnterActionsTrigger.ExitActionsStopStoryboard BeginStoryboardNameRoll_Storyboard//Trigger.ExitActions/Trigger/ControlTemplate.Triggers/ControlTemplate/Setter.Value/Setter
/Style
五、LoadingExample.xaml 代码如下  wpfdev:CycleLoading  Value50 LoadTitleLoading.... Width200TextBlock Textactivity//wpfdev:CycleLoadingwpfdev:RollLoading IsStarttrue HorizontalContentAlignmentCenter VerticalContentAlignmentCenterWidth200TextBlock TextLoading activity...//wpfdev:RollLoading
源码地址githubhttps://github.com/yanjinhuagood/WPFDevelopers.gitgiteehttps://gitee.com/yanjinhua/WPFDevelopers.gitWPF开发者QQ群 340500857 blogs https://www.cnblogs.com/yanjinhuaGithubhttps://github.com/yanjinhuagood出处https://www.cnblogs.com/yanjinhua版权本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。转载请著名作者 出处 https://github.com/yanjinhuagood