老板加薪!看我做的WPF Loading!!!

?老板加薪!看我做的WPF Loading!!!

控件名:RingLoading

作者:WPFDevelopersOrg

原文鏈接: ? ?https://github.com/WPFDevelopersOrg/WPFDevelopers.Minimal

  • 框架使用大于等于.NET40

  • Visual Studio 2022;

  • 項目使用 MIT 開源許可協議;

  • 最外層使用Viewbox為父控件內部嵌套創建三組 Grid -> Ellipse 、 Border 分別給它們指定不同的Angle從左側開始 -135 225 54,做永久 ?Angle 動畫;

  • 如何繪制;

40b9704197f21b8563500f55694e35a7.png
  • EllipseStrokeDashArray進行設置23 100就能達到效果;

1)RingLoading.cs代碼如下;

using?System.Windows;
using?System.Windows.Controls;namespace?WPFDevelopers.Controls
{public?class?RingLoading?:?Control{//?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(RingLoading),?new?PropertyMetadata(default));//?Using?a?DependencyProperty?as?the?backing?store?for?ProgressValue.??This?enables?animation,?styling,?binding,?etc...public?static?readonly?DependencyProperty?ProgressValueProperty?=DependencyProperty.Register("ProgressValue",?typeof(double),?typeof(RingLoading),new?PropertyMetadata(0d,?OnProgressValueChangedCallBack));//?Using?a?DependencyProperty?as?the?backing?store?for?Progress.??This?enables?animation,?styling,?binding,?etc...internal?static?readonly?DependencyProperty?ProgressProperty?=DependencyProperty.Register("Progress",?typeof(string),?typeof(RingLoading),?new?PropertyMetadata(default));//?Using?a?DependencyProperty?as?the?backing?store?for?Maximum.??This?enables?animation,?styling,?binding,?etc...public?static?readonly?DependencyProperty?MaximumProperty?=DependencyProperty.Register("Maximum",?typeof(double),?typeof(RingLoading),new?PropertyMetadata(100d,?OnMaximumPropertyChangedCallBack));//?Using?a?DependencyProperty?as?the?backing?store?for?Description.??This?enables?animation,?styling,?binding,?etc...public?static?readonly?DependencyProperty?DescriptionProperty?=DependencyProperty.Register("Description",?typeof(string),?typeof(RingLoading),new?PropertyMetadata(default));static?RingLoading(){DefaultStyleKeyProperty.OverrideMetadata(typeof(RingLoading),new?FrameworkPropertyMetadata(typeof(RingLoading)));}public?bool?IsStart{get?=>?(bool)GetValue(IsStartProperty);set?=>?SetValue(IsStartProperty,?value);}public?double?ProgressValue{get?=>?(double)GetValue(ProgressValueProperty);set?=>?SetValue(ProgressValueProperty,?value);}internal?string?Progress{get?=>?(string)GetValue(ProgressProperty);set?=>?SetValue(ProgressProperty,?value);}public?double?Maximum{get?=>?(double)GetValue(MaximumProperty);set?=>?SetValue(MaximumProperty,?value);}public?string?Description{get?=>?(string)GetValue(DescriptionProperty);set?=>?SetValue(DescriptionProperty,?value);}private?static?void?OnProgressValueChangedCallBack(DependencyObject?d,?DependencyPropertyChangedEventArgs?e){if?(!(d?is?RingLoading?control))return;if?(!double.TryParse(e.NewValue?.ToString(),?out?var?value))return;var?progress?=?value?/?control.Maximum;control.SetCurrentValue(ProgressProperty,?progress.ToString("P0"));}private?static?void?OnMaximumPropertyChangedCallBack(DependencyObject?d,?DependencyPropertyChangedEventArgs?e){if?(!(d?is?RingLoading?control))return;if?(!double.TryParse(e.NewValue?.ToString(),?out?var?maxValue))return;if?(maxValue?<=?0)return;var?progress?=?control.ProgressValue?/?maxValue;control.SetCurrentValue(ProgressProperty,?progress.ToString("P0"));}}
}

2)RingLoading.xaml代碼如下;

<Style?TargetType="controls:RingLoading"?BasedOn="{StaticResource?ControlBasicStyle}"><Setter?Property="Template"><Setter.Value><ControlTemplate?TargetType="controls:RingLoading"><ControlTemplate.Resources><Storyboard?x:Key="PART_Resource_Storyboard"?RepeatBehavior="Forever"><DoubleAnimation?To="-495"?Duration="0:0:1.5"?Storyboard.TargetName="PART_Ring1"??Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"/><DoubleAnimation?To="585"?Duration="0:0:1.5"?Storyboard.TargetName="PART_Ring2"??Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"/><DoubleAnimation?To="-315"?Duration="0:0:1.5"?Storyboard.TargetName="PART_Ring3"??Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"/></Storyboard></ControlTemplate.Resources><Grid><Grid.RowDefinitions><RowDefinition?Height="*"/><RowDefinition?Height="Auto"/></Grid.RowDefinitions><Viewbox?HorizontalAlignment="Center"?VerticalAlignment="Center"?><Border?Padding="10"?Width="100"?Height="100"?><Grid><Grid?x:Name="PART_Ring1"?Width="60"?Height="60"?HorizontalAlignment="Center"?VerticalAlignment="Top"?RenderTransformOrigin="0.5,0.5"><Grid.RenderTransform><TransformGroup><ScaleTransform/><SkewTransform/><RotateTransform?Angle="-135"/><TranslateTransform/></TransformGroup></Grid.RenderTransform><Ellipse?Stroke="Red"?StrokeThickness="2"?StrokeDashArray="23?100"?RenderTransformOrigin="0.5,0.5"/><Border?Width="10"?Height="10"?CornerRadius="10"?Background="Red"?HorizontalAlignment="Right"?Margin="0,0,-4,0"><Border.Effect><DropShadowEffect?BlurRadius="10"?ShadowDepth="0"?Color="Red"/></Border.Effect></Border></Grid><Grid?x:Name="PART_Ring2"?Width="60"?Height="60"?HorizontalAlignment="Left"?VerticalAlignment="Bottom"?RenderTransformOrigin="0.5,0.5"><Grid.RenderTransform><TransformGroup><ScaleTransform/><SkewTransform/><RotateTransform?Angle="225"/><TranslateTransform/></TransformGroup></Grid.RenderTransform><Ellipse?Stroke="Purple"?StrokeThickness="2"?StrokeDashArray="23?100"/><Border?Width="10"?Height="10"?CornerRadius="10"?Background="Purple"?VerticalAlignment="Bottom"?HorizontalAlignment="Center"?Margin="0,0,0,-4"><Border.Effect><DropShadowEffect?BlurRadius="10"?ShadowDepth="0"?Color="Purple"/></Border.Effect></Border></Grid><Grid?x:Name="PART_Ring3"?Width="60"?Height="60"?HorizontalAlignment="Right"?VerticalAlignment="Bottom"?RenderTransformOrigin="0.5,0.5"><Grid.RenderTransform><TransformGroup><ScaleTransform/><SkewTransform/><RotateTransform?Angle="45"/><TranslateTransform/></TransformGroup></Grid.RenderTransform><Ellipse?Stroke="#0fb8b2"?StrokeThickness="2"?StrokeDashArray="23?100"/><Border?Width="10"?Height="10"?CornerRadius="10"?Background="#0fb8b2"?HorizontalAlignment="Right"?Margin="0,0,-4,0"><Border.Effect><DropShadowEffect?BlurRadius="10"?ShadowDepth="0"?Color="#0fb8b2"/></Border.Effect></Border></Grid></Grid></Border></Viewbox><StackPanel?Grid.Row="1"?Grid.ColumnSpan="2"?Margin="10"><TextBlock?HorizontalAlignment="Center"?Text="Loading..."?Margin="0,0,0,15"/><TextBlock?HorizontalAlignment="Center"?Text="{TemplateBinding?Description}"?Margin="0,0,0,15"/><TextBlock?HorizontalAlignment="Center"?Text="{TemplateBinding?Progress}"?FontSize="{StaticResource?TitleFontSize}"?FontWeight="Bold"/></StackPanel></Grid><ControlTemplate.Triggers><Trigger?Property="IsStart"?Value="True"><Trigger.EnterActions><BeginStoryboard?Storyboard="{StaticResource?PART_Resource_Storyboard}"?x:Name="PART_BeginStoryboard"/></Trigger.EnterActions><Trigger.ExitActions><StopStoryboard?BeginStoryboardName="PART_BeginStoryboard"/></Trigger.ExitActions></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

3)RingLoadingExample.xaml代碼如下;

<UserControl?x:Class="WPFDevelopers.Samples.ExampleViews.RingLoadingExample"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:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"mc:Ignorable="d"?d:DesignHeight="450"?d:DesignWidth="800"><Grid><wpfdev:RingLoading?IsStart="true"?Width="400"?Height="400"Description="WPFDevelopers"?Foreground="Black"?ProgressValue="50"/></Grid>
</UserControl>

RingLoading|Github[1]
RingLoading|碼云[2]
RingLoading.xaml|Github[3]
RingLoading.xaml|碼云[4]

參考資料

[1]

ThemeControl|Github: https://github.com/WPFDevelopersOrg/WPFDevelopers/blob/master/src/WPFDevelopers/Controls/Loadings/RingLoading.cs

[2]

ThemeControl|碼云: https://gitee.com/WPFDevelopersOrg/WPFDevelopers/blob/master/src/WPFDevelopers/Controls/Loadings/RingLoading.cs

[3]

Styles.ThemeControl.xaml|Github: https://github.com/WPFDevelopersOrg/WPFDevelopers/blob/master/src/WPFDevelopers/Themes/LoadingGroup.xaml

[4]

Styles.ThemeControl.xaml|碼云: https://gitee.com/WPFDevelopersOrg/WPFDevelopers/blob/master/src/WPFDevelopers/Themes/LoadingGroup.xaml

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/283839.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/283839.shtml
英文地址,請注明出處:http://en.pswp.cn/news/283839.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何避免下重復訂單

電子交易的一個很基本的問題&#xff0c;就是避免用戶下重復訂單。用戶明明想買一次&#xff0c;結果一看下了兩個單。如果沒有及時發現&#xff0c;就會帶來額外的物流成本和扯皮。對商家的信譽也不好看。 從技術上看&#xff0c;這是一個分布式一致性問題&#xff1b;但實際…

圖像分類學習筆記

1.計算機認識圖像的方式&#xff1a;都是數字。例如一個 128X128 的3通道的圖片 是由 128X128X3個數字 組成的。 2.面臨的難點&#xff1a;一幅圖可以說明。 3.分類器 A&#xff1a;Nearest Neighbor Classifier&#xff1a;與CNN無關&#xff0c;但是可以幫助我們理解一下分類…

知物由學 | 干貨!一文了解安卓APP逆向分析與保護機制

“知物由學”是網易云易盾打造的一個品牌欄目&#xff0c;詞語出自漢王充《論衡實知》。人&#xff0c;能力有高下之分&#xff0c;學習才知道事物的道理&#xff0c;而后才有智慧&#xff0c;不去求問就不會知道。“知物由學”希望通過一篇篇技術干貨、趨勢解讀、人物思考和沉…

[轉]以終為始,詳細分析高考志愿該怎么填

為什么寫這篇文章&#xff1f; 之所以寫本文&#xff0c;是因為我自己有用處。 我簡要介紹&#xff0c;長話短說。我從一個普通的211本科畢業&#xff0c;已經接受社會"毒打"多年&#xff0c;回想起高考填志愿&#xff0c;依然會覺得有些許遺憾。我在貴州省的一個小縣…

ASP.NET Core 中的重定向

前言在《如何使用ASP.NET Core Web API實現短鏈接服務》中&#xff0c;我們使用了Redirect方法返回跳轉狀態碼:[HttpGet("{shortUrl}")] public IActionResult GetUrl(string shortUrl) {var hashids new Hashids("公眾號My IO", minHashLength: 6);var i…

C#IO

System.IO 命名空間包含允許讀寫文件和數據流的類型以及提供基本文件和目錄支持的類型。string url "C:\chisp.log";if (System.IO.File.Exists(url)){Response.Write("文件存在");}else{ Response.Write("文件不存在"); }System.IO.File.Exist…

Lind.DDD.Manager里的3,7,15,31,63,127,255,511,1023,2047

回到目錄 進制 我是一個程序猿&#xff0c;我喜歡簡單的數字&#xff0c;十進制如何&#xff0c;數字太多&#xff0c;有10種數字組成&#xff0c;但由于它廣為人知&#xff0c;所有使用最為廣泛&#xff0c;人們的慣性思維培養了十進制&#xff0c;并說它是最容易被計算的數字…

3.20學習內容,字符串與列表

一、字符串類型&#xff1a; 作用&#xff1a;名字&#xff0c;性別&#xff0c;國籍&#xff0c;地址等描述信息 定義&#xff1a;在單引號\雙引號\三引號內&#xff0c;由一串字符組成。 需要掌握的方法&#xff1a; 1、strip 去除指定字符lstrip 去除左邊指定字符rstri…

客戶端應用試用限制設計

1.概要最近接到公司安排的任務給客戶端設計一個“試用30天”的一個需求&#xff0c;其功能主要是為了防止客戶拿到產品之后不支付尾款繼續使用。眾所周知靠純軟件想防“盜版”&#xff0c;“限制試用”等做法是行業難題。只要價值足夠高一定有人會破解繞過你的所有防線達到免費…

【開發工具之Spring Tool Suite】6、用Spring Tool Suite簡化你的開發

如果你是一個喜歡用spring的人&#xff0c;你可能會在欣賞spring的強大功能外&#xff0c;對其各樣的配置比較郁悶&#xff0c;尤其是相差較大的版本在配置文件方面會存在差異&#xff0c;當然你可以去花不少的時間去網上查找相關的資料&#xff0c;當你準備使用更高版本spring…

康威定律,作為架構師還不會靈活運用?

Soft skills are always hard than hard skills. 軟技能比硬技能難。 老板聽說最近流行“微服務”&#xff0c;問架構師咱們的系統要不要來一套&#xff1f;老板又聽說最近流行“中臺系統”&#xff0c;問架構師咱們要不要搞起來&#xff1f;其實&#xff0c;這些問題不用老板問…

使用onclick跳轉到其他頁面。使用button跳轉到指定url

1. οnclick"javascript:window.location.hrefaa.htm" 2. οnclick"locationURL"3,。 οnclick"window.location.href?id11"轉載于:https://www.cnblogs.com/wujixing/p/5856087.html

Avalonia Beta 1對WPF做了很多改進

\看新聞很累&#xff1f;看技術新聞更累&#xff1f;試試下載InfoQ手機客戶端&#xff0c;每天上下班路上聽新聞&#xff0c;有趣還有料&#xff01;\\\Avalonia將自己定義為“基于WPF&#xff08;使用XAML、數據綁定以及lookless控件等&#xff09;的跨平臺.NET UI框架。”在第…

WebView2 通過 PuppeteerSharp 實現RPA獲取壁紙 (案例版)

此案例是《.Net WebView2 項目&#xff0c;實現 嵌入 WEB 頁面 Chromium內核》文的續集。主要是針對WebView2的一些微軟自己封裝的不熟悉的API&#xff0c;有一些人已經對 PuppeteerSharp很熟悉了&#xff0c;那么&#xff0c;直接用 PuppeteerSharp的話&#xff0c;那就降低了…

[轉]2022 年 Java 行業分析報告

你好&#xff0c;我是看山。 前段時間介紹了從 Java8 到 Java17 每個版本比較有特點的新特性&#xff08;收錄在 從小工到專家的 Java 進階之旅 專欄&#xff09;&#xff0c;今天看到 JRebel 發布了《2022 年 Java 發展趨勢和分析》&#xff0c;于是借此分析一下 Java 行業的現…

Mysql 數據庫學習筆記03 存儲過程

一、存儲過程&#xff1a;如下 通過 out 、inout 將結果輸出&#xff0c;可以輸出多個值。 * 調用存儲過程&#xff1a; call 存儲名稱&#xff08;參數1&#xff0c;參數2&#xff0c;...&#xff09;; 如指定參數不符合要求&#xff0c;返回 Empty Set * 查詢存儲過…

android 代碼混淆模板

#指定代碼的壓縮級別 -optimizationpasses 5 #包明不混合大小寫 -dontusemixedcaseclassnames #不去忽略非公共的庫類 -dontskipnonpubliclibraryclasses#優化 不優化輸入的類文件 -dontoptimize#預校驗 -dontpreverify#混淆時是否記錄日志 -verbose# 混淆時所采用的算法 -opt…

vue+vuecli+webapck2實現多頁面應用

準備工作 在本地用vue-cli新建一個項目&#xff0c;首先安裝vue-cil&#xff0c;命令&#xff1a; npm install -g vue-cli 新建一個vue項目,創建一個基于"webpack"的項目,項目名為vuedemo&#xff1a; vue init webpack vuedemo 這里有一個地方需要改一下&#xff0…

一文把Docker、Kubernetes搞懂:什么是Docker?什么是Kubernetes?Docker和Kubernetes有什么關系和區別?通俗解釋Docker、Kubernetes

一、Docker解決的問題 1、統一標準 ● 應用構建 ○ Java、C、JavaScript——編程各異 ○ 打成軟件包 ○ .exe&#xff08;類似Windows&#xff0c;最終也只是生產exe執行&#xff09; ○ 使用docker build … 打包成 鏡像——這就類似于exe ● 應用分享 ○ 所有軟件的鏡像放到一…

Python-高階函數

#encodingUTF-8import sys # 高階函數高階函數實際上是參數可接受函數的函數即參數為函數的函數 # map()map()接收兩個參數&#xff0c;一個是函數&#xff0c;一個是序列&#xff0c;將此函數分別作用于該序列的每個元素&#xff0c;返回處理后的序列結果def c2(x): return x…