日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

WPF任务栏同步进度

發布時間:2023/12/4 asp.net 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF任务栏同步进度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、概要

本篇文章主要分享使用TaskbarItemInfo對象(WPF)在window操作系統的任務欄中同步任務進度的功能。

什么是TaskbarItemInfo對象?

TaskbarItemInfo類為 Windows 7 任務欄功能提供托管包裝。有關 Windows shell 和本機任務欄 Api 的詳細信息,其中taskbar的縮略圖操作界面和任務進度更新就是其中的兩個部分功能。

  • 參考資料:https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.shell.taskbariteminfo?f1url=%3FappId%3DDev16IDEF1%26l%3DZH-CN%26k%3Dk(System.Windows.Shell.TaskbarItemInfo);k(VS.XamlEditor)%26rd%3Dtrue&view=net-5.0

  • 源碼地址:https://github.com/JusterZhu/2021PlanJ

二、實現

xaml代碼

<Window x:Class="TaskProgressBar.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:TaskProgressBar" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Title="MainWindow" Width="800" Height="450" mc:Ignorable="d"> <Window.TaskbarItemInfo><TaskbarItemInfo ProgressState="Normal" /> </Window.TaskbarItemInfo><Grid><StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"><ProgressBarx:Name="MyProgressBar"Width="400"Height="30" /><Buttonx:Name="MyBtn"Width="80"Height="25"Margin="10"Click="MyBtn_Click"Content="Start" /></StackPanel></Grid> </Window>

TaskbarItemInfo對象中ProgressState枚舉字段。我們這里只是正常的顯示進度那么枚舉為Normal即可。

  • Error 3
    任務欄按鈕中顯示紅色的進度指示器。

  • Indeterminate 1
    任務欄按鈕中顯示閃爍的綠色進度指示器。

  • None 0
    任務欄按鈕中未顯示進度指示器。

  • Normal 2
    任務欄按鈕中顯示綠色的進度指示器。

  • Paused 4
    任務欄按鈕中顯示黃色的進度指示器。

c#代碼

public MainWindow(){InitializeComponent();MyProgressBar.Minimum = 0;MyProgressBar.Maximum = 100;}private async void Update(){while (true){if (MyProgressBar.Value == MyProgressBar.Maximum){break;}MyProgressBar.Value += 10;TaskbarItemInfo.ProgressValue = MyProgressBar.Value / MyProgressBar.Maximum;await Task.Delay(500);}}private void MyBtn_Click(object sender, RoutedEventArgs e){Update();}

總結

以上是生活随笔為你收集整理的WPF任务栏同步进度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。