├── .gitattributes ├── .gitignore ├── 1.gif ├── 2.gif ├── ProgressControlSample ├── ProgressControlSample.sln ├── ProgressControlSample.sln.DotSettings └── ProgressControlSample │ ├── App.xaml │ ├── App.xaml.cs │ ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png │ ├── BasicPage.xaml │ ├── BasicPage.xaml.cs │ ├── Behaviors │ ├── AdjustToSquareBehavior.cs │ ├── EllipseProgressBehavior.cs │ ├── ProgressBehavior.cs │ ├── RectangleToEllipseBehavior.cs │ └── RelativeOffsetBehavior.cs │ ├── Converter │ └── BorderToStrokeThicknessConverter.cs │ ├── Download │ ├── AddDownloadDialog.xaml │ ├── AddDownloadDialog.xaml.cs │ ├── DownloadPage.xaml │ ├── DownloadPage.xaml.cs │ ├── DownloadServiceClient.cs │ ├── Downloader.cs │ └── DownloaderModel.cs │ ├── FrameworkElementExtensions.cs │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── Package.appxmanifest │ ├── ProgressControl │ ├── ProgressControl.Constants.cs │ ├── ProgressControl.cs │ ├── ProgressState.cs │ └── ProgressStateEventArgs.cs │ ├── ProgressControlSample.csproj │ ├── ProgressStateIndicator │ ├── ProgressStateIndicator.Constants.cs │ └── ProgressStateIndicator.cs │ ├── Properties │ ├── Annotations.cs │ ├── AssemblyInfo.cs │ └── Default.rd.xml │ ├── SizeBridge.cs │ ├── TestService.cs │ └── Themes │ └── Generic.xaml └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/1.gif -------------------------------------------------------------------------------- /2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/2.gif -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgressControlSample", "ProgressControlSample\ProgressControlSample.csproj", "{D115F213-6A7F-40B8-93A2-7ED1BB672701}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM = Debug|ARM 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|ARM = Release|ARM 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|ARM.ActiveCfg = Debug|ARM 19 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|ARM.Build.0 = Debug|ARM 20 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|ARM.Deploy.0 = Debug|ARM 21 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|x64.ActiveCfg = Debug|x64 22 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|x64.Build.0 = Debug|x64 23 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|x64.Deploy.0 = Debug|x64 24 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|x86.ActiveCfg = Debug|x86 25 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|x86.Build.0 = Debug|x86 26 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Debug|x86.Deploy.0 = Debug|x86 27 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|ARM.ActiveCfg = Release|ARM 28 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|ARM.Build.0 = Release|ARM 29 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|ARM.Deploy.0 = Release|ARM 30 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|x64.ActiveCfg = Release|x64 31 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|x64.Build.0 = Release|x64 32 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|x64.Deploy.0 = Release|x64 33 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|x86.ActiveCfg = Release|x86 34 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|x86.Build.0 = Release|x86 35 | {D115F213-6A7F-40B8-93A2-7ED1BB672701}.Release|x86.Deploy.0 = Release|x86 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {1A045F4C-0C97-4632-BE1E-E1AFCB3DFB4F} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using System.Threading; 7 | using Windows.ApplicationModel; 8 | using Windows.ApplicationModel.Activation; 9 | using Windows.Foundation; 10 | using Windows.Foundation.Collections; 11 | using Windows.UI.Popups; 12 | using Windows.UI.Xaml; 13 | using Windows.UI.Xaml.Controls; 14 | using Windows.UI.Xaml.Controls.Primitives; 15 | using Windows.UI.Xaml.Data; 16 | using Windows.UI.Xaml.Input; 17 | using Windows.UI.Xaml.Media; 18 | using Windows.UI.Xaml.Navigation; 19 | 20 | namespace ProgressControlSample 21 | { 22 | /// 23 | /// 提供特定于应用程序的行为,以补充默认的应用程序类。 24 | /// 25 | sealed partial class App : Application 26 | { 27 | /// 28 | /// 初始化单一实例应用程序对象。这是执行的创作代码的第一行, 29 | /// 已执行,逻辑上等同于 main() 或 WinMain()。 30 | /// 31 | public App() 32 | { 33 | this.InitializeComponent(); 34 | this.Suspending += OnSuspending; 35 | } 36 | 37 | /// 38 | /// 在应用程序由最终用户正常启动时进行调用。 39 | /// 将在启动应用程序以打开特定文件等情况下使用。 40 | /// 41 | /// 有关启动请求和过程的详细信息。 42 | protected override void OnLaunched(LaunchActivatedEventArgs e) 43 | { 44 | Frame rootFrame = Window.Current.Content as Frame; 45 | 46 | // 不要在窗口已包含内容时重复应用程序初始化, 47 | // 只需确保窗口处于活动状态 48 | if (rootFrame == null) 49 | { 50 | // 创建要充当导航上下文的框架,并导航到第一页 51 | rootFrame = new Frame(); 52 | 53 | rootFrame.NavigationFailed += OnNavigationFailed; 54 | 55 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 56 | { 57 | //TODO: 从之前挂起的应用程序加载状态 58 | } 59 | 60 | // 将框架放在当前窗口中 61 | Window.Current.Content = rootFrame; 62 | } 63 | 64 | if (e.PrelaunchActivated == false) 65 | { 66 | if (rootFrame.Content == null) 67 | { 68 | // 当导航堆栈尚未还原时,导航到第一页, 69 | // 并通过将所需信息作为导航参数传入来配置 70 | // 参数 71 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 72 | } 73 | // 确保当前窗口处于活动状态 74 | Window.Current.Activate(); 75 | } 76 | 77 | RegisterExceptionHandlingSynchronizationContext(); 78 | } 79 | 80 | /// 81 | /// 导航到特定页失败时调用 82 | /// 83 | ///导航失败的框架 84 | ///有关导航失败的详细信息 85 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 86 | { 87 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 88 | } 89 | 90 | /// 91 | /// 在将要挂起应用程序执行时调用。 在不知道应用程序 92 | /// 无需知道应用程序会被终止还是会恢复, 93 | /// 并让内存内容保持不变。 94 | /// 95 | /// 挂起的请求的源。 96 | /// 有关挂起请求的详细信息。 97 | private void OnSuspending(object sender, SuspendingEventArgs e) 98 | { 99 | var deferral = e.SuspendingOperation.GetDeferral(); 100 | //TODO: 保存应用程序状态并停止任何后台活动 101 | deferral.Complete(); 102 | } 103 | 104 | private void RegisterExceptionHandlingSynchronizationContext() 105 | { 106 | ExceptionHandlingSynchronizationContext 107 | .Register() 108 | .UnhandledException += SynchronizationContext_UnhandledException; 109 | } 110 | 111 | private async void SynchronizationContext_UnhandledException(object sender, UnhandledExceptionEventArgs e) 112 | { 113 | e.Handled = true; 114 | await new MessageDialog("Synchronization Context Unhandled Exception:\r\n" + e.Exception.Message, "爆了 :(") 115 | .ShowAsync(); 116 | } 117 | } 118 | 119 | public class ExceptionHandlingSynchronizationContext : SynchronizationContext 120 | { 121 | /// 122 | /// Registration method. Call this from OnLaunched and OnActivated inside the App.xaml.cs 123 | /// 124 | /// 125 | public static ExceptionHandlingSynchronizationContext Register() 126 | { 127 | var syncContext = Current; 128 | if (syncContext == null) 129 | throw new InvalidOperationException("Ensure a synchronization context exists before calling this method."); 130 | 131 | 132 | var customSynchronizationContext = syncContext as ExceptionHandlingSynchronizationContext; 133 | 134 | 135 | if (customSynchronizationContext == null) 136 | { 137 | customSynchronizationContext = new ExceptionHandlingSynchronizationContext(syncContext); 138 | SetSynchronizationContext(customSynchronizationContext); 139 | } 140 | 141 | 142 | return customSynchronizationContext; 143 | } 144 | 145 | /// 146 | /// Links the synchronization context to the specified frame 147 | /// and ensures that it is still in use after each navigation event 148 | /// 149 | /// 150 | /// 151 | public static ExceptionHandlingSynchronizationContext RegisterForFrame(Frame rootFrame) 152 | { 153 | if (rootFrame == null) 154 | throw new ArgumentNullException(nameof(rootFrame)); 155 | 156 | var synchronizationContext = Register(); 157 | 158 | rootFrame.Navigating += (sender, args) => EnsureContext(synchronizationContext); 159 | rootFrame.Loaded += (sender, args) => EnsureContext(synchronizationContext); 160 | 161 | return synchronizationContext; 162 | } 163 | 164 | private static void EnsureContext(SynchronizationContext context) 165 | { 166 | if (Current != context) 167 | SetSynchronizationContext(context); 168 | } 169 | 170 | 171 | private readonly SynchronizationContext _syncContext; 172 | 173 | 174 | public ExceptionHandlingSynchronizationContext(SynchronizationContext syncContext) 175 | { 176 | _syncContext = syncContext; 177 | } 178 | 179 | 180 | public override SynchronizationContext CreateCopy() 181 | { 182 | return new ExceptionHandlingSynchronizationContext(_syncContext.CreateCopy()); 183 | } 184 | 185 | 186 | public override void OperationCompleted() 187 | { 188 | _syncContext.OperationCompleted(); 189 | } 190 | 191 | 192 | public override void OperationStarted() 193 | { 194 | _syncContext.OperationStarted(); 195 | } 196 | 197 | 198 | public override void Post(SendOrPostCallback d, object state) 199 | { 200 | _syncContext.Post(WrapCallback(d), state); 201 | } 202 | 203 | 204 | public override void Send(SendOrPostCallback d, object state) 205 | { 206 | _syncContext.Send(d, state); 207 | } 208 | 209 | 210 | private SendOrPostCallback WrapCallback(SendOrPostCallback sendOrPostCallback) 211 | { 212 | return state => 213 | { 214 | try 215 | { 216 | sendOrPostCallback(state); 217 | } 218 | catch (Exception ex) 219 | { 220 | if (!HandleException(ex)) 221 | throw; 222 | } 223 | }; 224 | } 225 | 226 | private bool HandleException(Exception exception) 227 | { 228 | if (UnhandledException == null) 229 | return false; 230 | 231 | var exWrapper = new UnhandledExceptionEventArgs 232 | { 233 | Exception = exception 234 | }; 235 | 236 | UnhandledException(this, exWrapper); 237 | 238 | #if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION 239 | if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); 240 | #endif 241 | 242 | return exWrapper.Handled; 243 | } 244 | 245 | 246 | /// 247 | /// Listen to this event to catch any unhandled exceptions and allow for handling them 248 | /// so they don't crash your application 249 | /// 250 | public event EventHandler UnhandledException; 251 | } 252 | 253 | public class UnhandledExceptionEventArgs : EventArgs 254 | { 255 | public bool Handled { get; set; } 256 | public Exception Exception { get; set; } 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/StoreLogo.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DinoChan/Progress-Control-Sample/8b622412d490d7cf300e3d70b2084be187ad2181/ProgressControlSample/ProgressControlSample/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/BasicPage.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 33 | 35 | 36 | 37 | 42 | 56 | 61 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/BasicPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using System.Threading.Tasks; 7 | using Windows.Foundation; 8 | using Windows.Foundation.Collections; 9 | using Windows.UI.Xaml; 10 | using Windows.UI.Xaml.Controls; 11 | using Windows.UI.Xaml.Controls.Primitives; 12 | using Windows.UI.Xaml.Data; 13 | using Windows.UI.Xaml.Input; 14 | using Windows.UI.Xaml.Media; 15 | using Windows.UI.Xaml.Navigation; 16 | 17 | //https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板 18 | 19 | namespace ProgressControlSample 20 | { 21 | public sealed partial class BasicPage : UserControl 22 | { 23 | private TestService _faultTestService; 24 | private TestService _testService; 25 | 26 | public BasicPage() 27 | { 28 | this.InitializeComponent(); 29 | StateListView.Items.Add(new ListViewItem { Content = "Ready", Tag = ProgressState.Ready }); 30 | StateListView.Items.Add(new ListViewItem { Content = "Started", Tag = ProgressState.Started }); 31 | StateListView.Items.Add(new ListViewItem { Content = "Paused", Tag = ProgressState.Paused }); 32 | StateListView.Items.Add(new ListViewItem { Content = "Completed", Tag = ProgressState.Completed }); 33 | StateListView.Items.Add(new ListViewItem { Content = "Fault", Tag = ProgressState.Faulted }); 34 | StateListView.SelectedIndex = 0; 35 | _faultTestService = new TestService(); 36 | _testService = new TestService(); 37 | } 38 | 39 | private async void ProgressControlStateChanged(object sender, ProgressStateEventArgs e) 40 | { 41 | switch (e.NewValue) 42 | { 43 | case ProgressState.Ready: 44 | _testService = new TestService(); 45 | ProgressControl.Value = ProgressControl.Minimum; 46 | break; 47 | case ProgressState.Started: 48 | try 49 | { 50 | _testService.IsPaused = false; 51 | _testService.ProgressChanged += (s, args) => { ProgressControl.Value = args; }; 52 | await _testService.Start(); 53 | if (_testService.IsCompleted) 54 | ProgressControl.State = ProgressState.Completed; 55 | } 56 | catch (Exception) 57 | { 58 | ProgressControl.State = ProgressState.Faulted; 59 | } 60 | break; 61 | case ProgressState.Paused: 62 | _testService.IsPaused = true; 63 | break; 64 | case ProgressState.Completed: 65 | break; 66 | case ProgressState.Faulted: 67 | break; 68 | } 69 | } 70 | 71 | 72 | 73 | private async void FaultProgressControlStateChanged(object sender, ProgressStateEventArgs e) 74 | { 75 | switch (e.NewValue) 76 | { 77 | case ProgressState.Ready: 78 | _faultTestService = new TestService(); 79 | FaultProgressControl.Value = FaultProgressControl.Minimum; 80 | break; 81 | case ProgressState.Started: 82 | try 83 | { 84 | _faultTestService.IsPaused = false; 85 | _faultTestService.ProgressChanged += (s, args) => { FaultProgressControl.Value = args; }; 86 | await _faultTestService.Start(true); 87 | if (_faultTestService.IsCompleted) 88 | FaultProgressControl.State = ProgressState.Completed; 89 | } 90 | catch (Exception) 91 | { 92 | FaultProgressControl.State = ProgressState.Faulted; 93 | } 94 | break; 95 | case ProgressState.Paused: 96 | _faultTestService.IsPaused = true; 97 | break; 98 | case ProgressState.Completed: 99 | break; 100 | case ProgressState.Faulted: 101 | break; 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Behaviors/AdjustToSquareBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Windows.Foundation; 7 | using Windows.UI.Xaml; 8 | using Windows.UI.Xaml.Controls; 9 | 10 | namespace ProgressControlSample 11 | { 12 | public class AdjustToSquareBehavior : ProgressBehavior 13 | { 14 | private Size _originalSize; 15 | 16 | /// 17 | /// 获取或设置ContentElement的值 18 | /// 19 | public FrameworkElement ContentElement 20 | { 21 | get { return (FrameworkElement)GetValue(ContentElementProperty); } 22 | set { SetValue(ContentElementProperty, value); } 23 | } 24 | 25 | /// 26 | /// 标识 ContentElement 依赖属性。 27 | /// 28 | public static readonly DependencyProperty ContentElementProperty = 29 | DependencyProperty.Register("ContentElement", typeof(FrameworkElement), typeof(AdjustToSquareBehavior), new PropertyMetadata(null, OnContentElementChanged)); 30 | 31 | private static void OnContentElementChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 32 | { 33 | AdjustToSquareBehavior target = obj as AdjustToSquareBehavior; 34 | FrameworkElement oldValue = (FrameworkElement)args.OldValue; 35 | FrameworkElement newValue = (FrameworkElement)args.NewValue; 36 | if (oldValue != newValue) 37 | target.OnContentElementChanged(oldValue, newValue); 38 | } 39 | 40 | protected virtual void OnContentElementChanged(FrameworkElement oldValue, FrameworkElement newValue) 41 | { 42 | if (oldValue != null) 43 | newValue.SizeChanged -= OnContentElementSizeChanged; 44 | 45 | if (newValue != null) 46 | { 47 | newValue.SizeChanged += OnContentElementSizeChanged; 48 | if (Progress == 0) 49 | _originalSize = newValue.RenderSize; 50 | 51 | UpdateTargetSize(); 52 | } 53 | 54 | } 55 | 56 | private void OnContentElementSizeChanged(object sender, SizeChangedEventArgs e) 57 | { 58 | if (Progress == 0) 59 | _originalSize = e.NewSize; 60 | 61 | UpdateTargetSize(); 62 | } 63 | 64 | protected override void OnProgressChanged(double oldValue, double newValue) 65 | { 66 | UpdateTargetSize(); 67 | } 68 | 69 | 70 | private void UpdateTargetSize() 71 | { 72 | if (ContentElement == null) 73 | return; 74 | 75 | if (AssociatedObject == null) 76 | return; 77 | 78 | if (_originalSize.Width == 0 || _originalSize.Height == 0 || double.IsNaN(Progress)) 79 | return; 80 | 81 | var width = _originalSize.Width; 82 | var height = _originalSize.Height; 83 | if (width > height) 84 | { 85 | AssociatedObject.Width = width - (width - height) * Progress; 86 | AssociatedObject.Height = height; 87 | } 88 | else 89 | { 90 | AssociatedObject.Height = height - (height - width) * Progress; 91 | AssociatedObject.Width = width; 92 | } 93 | 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Behaviors/EllipseProgressBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.Xaml.Interactivity; 7 | using Windows.UI.Xaml; 8 | using Windows.UI.Xaml.Controls.Primitives; 9 | using Windows.UI.Xaml.Media; 10 | using Windows.UI.Xaml.Shapes; 11 | 12 | namespace ProgressControlSample 13 | { 14 | public class EllipseProgressBehavior : Behavior 15 | { 16 | /// 17 | /// 获取或设置Value的值 18 | /// 19 | public double Value 20 | { 21 | get { return (double)GetValue(ValueProperty); } 22 | set { SetValue(ValueProperty, value); } 23 | } 24 | 25 | /// 26 | /// 标识 Value 依赖属性。 27 | /// 28 | public static readonly DependencyProperty ValueProperty = 29 | DependencyProperty.Register("Value", typeof(double), typeof(EllipseProgressBehavior), new PropertyMetadata(0d, OnValueChanged)); 30 | 31 | private static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 32 | { 33 | EllipseProgressBehavior target = obj as EllipseProgressBehavior; 34 | double oldValue = (double)args.OldValue; 35 | double newValue = (double)args.NewValue; 36 | if (oldValue != newValue) 37 | target.OnValueChanged(oldValue, newValue); 38 | } 39 | 40 | protected virtual void OnValueChanged(double oldValue, double newValue) 41 | { 42 | UpdateStrokeDashArray(); 43 | } 44 | 45 | /// 46 | /// 获取或设置Maximum的值 47 | /// 48 | public double Maximum 49 | { 50 | get { return (double)GetValue(MaximumProperty); } 51 | set { SetValue(MaximumProperty, value); } 52 | } 53 | 54 | /// 55 | /// 标识 Maximum 依赖属性。 56 | /// 57 | public static readonly DependencyProperty MaximumProperty = 58 | DependencyProperty.Register("Maximum", typeof(double), typeof(EllipseProgressBehavior), new PropertyMetadata(100d, OnMaximumChanged)); 59 | 60 | private static void OnMaximumChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 61 | { 62 | EllipseProgressBehavior target = obj as EllipseProgressBehavior; 63 | double oldValue = (double)args.OldValue; 64 | double newValue = (double)args.NewValue; 65 | if (oldValue != newValue) 66 | target.OnMaximumChanged(oldValue, newValue); 67 | } 68 | 69 | protected virtual void OnMaximumChanged(double oldValue, double newValue) 70 | { 71 | UpdateStrokeDashArray(); 72 | } 73 | 74 | /// 75 | /// 获取或设置Minimum的值 76 | /// 77 | public double Minimum 78 | { 79 | get { return (double)GetValue(MinimumProperty); } 80 | set { SetValue(MinimumProperty, value); } 81 | } 82 | 83 | /// 84 | /// 标识 Minimum 依赖属性。 85 | /// 86 | public static readonly DependencyProperty MinimumProperty = 87 | DependencyProperty.Register("Minimum", typeof(double), typeof(EllipseProgressBehavior), new PropertyMetadata(0d, OnMinimumChanged)); 88 | 89 | private static void OnMinimumChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 90 | { 91 | EllipseProgressBehavior target = obj as EllipseProgressBehavior; 92 | double oldValue = (double)args.OldValue; 93 | double newValue = (double)args.NewValue; 94 | if (oldValue != newValue) 95 | target.OnMinimumChanged(oldValue, newValue); 96 | } 97 | 98 | protected virtual void OnMinimumChanged(double oldValue, double newValue) 99 | { 100 | UpdateStrokeDashArray(); 101 | } 102 | 103 | protected override void OnAttached() 104 | { 105 | base.OnAttached(); 106 | UpdateStrokeDashArray(); 107 | } 108 | 109 | protected virtual double GetTotalLength() 110 | { 111 | if (AssociatedObject == null) 112 | return 0; 113 | 114 | return (AssociatedObject.ActualHeight - AssociatedObject.StrokeThickness) * Math.PI; 115 | } 116 | 117 | 118 | private void UpdateStrokeDashArray() 119 | { 120 | if (AssociatedObject == null || AssociatedObject.StrokeThickness == 0) 121 | return; 122 | 123 | var totalLength = GetTotalLength(); 124 | totalLength = totalLength / AssociatedObject.StrokeThickness; 125 | var total = Maximum - Minimum; 126 | if (total <= 0) 127 | total = 1; 128 | 129 | var progress = (Value - Minimum) / total; 130 | var section = progress * totalLength; 131 | var result = new DoubleCollection { section, double.MaxValue }; 132 | AssociatedObject.StrokeDashArray = result; 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Behaviors/ProgressBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Windows.UI.Xaml; 7 | using Microsoft.Xaml.Interactivity; 8 | 9 | namespace ProgressControlSample 10 | { 11 | public class ProgressBehavior : Behavior where T : DependencyObject 12 | { 13 | /// 14 | /// 获取或设置Progress的值 15 | /// 16 | public double Progress 17 | { 18 | get { return (double)GetValue(ProgressProperty); } 19 | set { SetValue(ProgressProperty, value); } 20 | } 21 | 22 | /// 23 | /// 标识 Progress 依赖属性。 24 | /// 25 | public static readonly DependencyProperty ProgressProperty = 26 | DependencyProperty.Register("Progress", typeof(double), typeof(ProgressBehavior), new PropertyMetadata(default(double), OnProgressChanged)); 27 | 28 | private static void OnProgressChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 29 | { 30 | ProgressBehavior target = obj as ProgressBehavior; 31 | double oldValue = (double)args.OldValue; 32 | double newValue = (double)args.NewValue; 33 | if (oldValue != newValue) 34 | target.OnProgressChanged(oldValue, newValue); 35 | } 36 | 37 | protected virtual void OnProgressChanged(double oldValue, double newValue) 38 | { 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Behaviors/RectangleToEllipseBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Windows.UI.Xaml.Shapes; 7 | 8 | namespace ProgressControlSample 9 | { 10 | public class RectangleToEllipseBehavior : ProgressBehavior 11 | { 12 | protected override void OnProgressChanged(double oldValue, double newValue) 13 | { 14 | UpdateStrokeDashArray(); 15 | } 16 | 17 | protected override void OnAttached() 18 | { 19 | base.OnAttached(); 20 | UpdateStrokeDashArray(); 21 | } 22 | 23 | 24 | private void UpdateStrokeDashArray() 25 | { 26 | if (AssociatedObject == null || AssociatedObject.ActualHeight == 0 || AssociatedObject.ActualWidth == 0) 27 | return; 28 | 29 | var radius = Math.Min(AssociatedObject.ActualHeight, AssociatedObject.ActualWidth) / 2; 30 | radius = radius * Progress; 31 | AssociatedObject.RadiusX = radius; 32 | AssociatedObject.RadiusY = radius; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Behaviors/RelativeOffsetBehavior.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Toolkit.Uwp.UI.Animations; 2 | using Microsoft.Xaml.Interactivity; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Windows.UI.Xaml; 9 | 10 | namespace ProgressControlSample 11 | { 12 | public class RelativeOffsetBehavior : Behavior 13 | { 14 | 15 | /// 16 | /// 获取或设置OffsetX的值 17 | /// 18 | public double OffsetX 19 | { 20 | get { return (double)GetValue(OffsetXProperty); } 21 | set { SetValue(OffsetXProperty, value); } 22 | } 23 | 24 | /// 25 | /// 标识 OffsetX 依赖属性。 26 | /// 27 | public static readonly DependencyProperty OffsetXProperty = 28 | DependencyProperty.Register("OffsetX", typeof(double), typeof(RelativeOffsetBehavior), new PropertyMetadata(0d, OnOffsetXChanged)); 29 | 30 | private static void OnOffsetXChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 31 | { 32 | RelativeOffsetBehavior target = obj as RelativeOffsetBehavior; 33 | double oldValue = (double)args.OldValue; 34 | double newValue = (double)args.NewValue; 35 | if (oldValue != newValue) 36 | target.OnOffsetXChanged(oldValue, newValue); 37 | } 38 | 39 | protected virtual void OnOffsetXChanged(double oldValue, double newValue) 40 | { 41 | UpdateOffset(); 42 | } 43 | 44 | 45 | /// 46 | /// 获取或设置OffsetY的值 47 | /// 48 | public double OffsetY 49 | { 50 | get { return (double)GetValue(OffsetYProperty); } 51 | set { SetValue(OffsetYProperty, value); } 52 | } 53 | 54 | /// 55 | /// 标识 OffsetY 依赖属性。 56 | /// 57 | public static readonly DependencyProperty OffsetYProperty = 58 | DependencyProperty.Register("OffsetY", typeof(double), typeof(RelativeOffsetBehavior), new PropertyMetadata(0d, OnOffsetYChanged)); 59 | 60 | private static void OnOffsetYChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 61 | { 62 | RelativeOffsetBehavior target = obj as RelativeOffsetBehavior; 63 | double oldValue = (double)args.OldValue; 64 | double newValue = (double)args.NewValue; 65 | if (oldValue != newValue) 66 | target.OnOffsetYChanged(oldValue, newValue); 67 | } 68 | 69 | protected virtual void OnOffsetYChanged(double oldValue, double newValue) 70 | { 71 | UpdateOffset(); 72 | } 73 | 74 | private void UpdateOffset() 75 | { 76 | if (AssociatedObject != null) 77 | { 78 | var offsetX = (float)(AssociatedObject.ActualWidth * OffsetX); 79 | var offsetY = (float)(AssociatedObject.ActualHeight * OffsetY); 80 | var animationSet = AssociatedObject.Offset(offsetX, offsetY, duration: 0, easingType: EasingType.Default); 81 | animationSet?.Start(); 82 | } 83 | } 84 | 85 | protected override void OnAttached() 86 | { 87 | base.OnAttached(); 88 | UpdateOffset(); 89 | if (AssociatedObject != null) 90 | AssociatedObject.SizeChanged += (s, e) => UpdateOffset(); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Converter/BorderToStrokeThicknessConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Windows.UI.Xaml; 7 | using Windows.UI.Xaml.Data; 8 | 9 | namespace ProgressControlSample 10 | { 11 | public class BorderToStrokeThicknessConverter : IValueConverter 12 | { 13 | public object Convert(object value, Type targetType, object parameter, string language) 14 | { 15 | var thickness = (Thickness)value; 16 | var max = Math.Max(thickness.Left, thickness.Top); 17 | max = Math.Max(max, thickness.Right); 18 | max = Math.Max(max, thickness.Bottom); 19 | return max; 20 | } 21 | 22 | public object ConvertBack(object value, Type targetType, object parameter, string language) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ProgressControlSample/ProgressControlSample/Download/AddDownloadDialog.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 28 | 29 | 30 | 32 | 33 | 35 | 36 | 37 | 39 | 40 | 42 | 43 | 44 | 45 | 50 | 51 | 57 | 61 | 66 |