--- lang: ja-jp breaks: true --- # UWP 処理状況ダイアログを出す プログレス コントロール 2021-04-14 > 「処理中ですよ」のプログレスリングダイアログを出して、勝手に閉じさせる方法 > https://tiratom.hatenablog.com/entry/2019/03/18/_%E3%80%8C%E5%87%A6%E7%90%86%E4%B8%AD%E3%81%A7%E3%81%99%E3%82%88%E3%80%8D%E3%81%AE%E3%83%97%E3%83%AD%E3%82%B0%E3%83%AC%E3%82%B9%E3%83%AA%E3%83%B3%E3%82%B0%E3%83%80%E3%82%A4%E3%82%A2%E3%83%AD%E3%82%B0 > ダイアログ コントロール > https://docs.microsoft.com/ja-jp/windows/uwp/design/controls-and-patterns/dialogs-and-flyouts/dialogs > プログレス コントロール > https://docs.microsoft.com/ja-jp/windows/uwp/design/controls-and-patterns/progress-controls ## 環境 * Windows Server 2019 * Visual Studio 2019 * Microsoft.NETCore.UniversalWindowsPlatform 6.2.11 ## プログレスリングを表示するダイアログ(コンテンツダイアログ)を作成  ```xaml= <ContentDialog x:Class="App8.alte.imple.csv_converter.dialog.ProgressDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App8.alte.imple.csv_converter.dialog" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="~処理中..." Background="{ThemeResource SystemControlChromeMediumLowAcrylicWindowMediumBrush}" > <Grid> <ProgressRing Width="50" Height="50" HorizontalAlignment="Center" IsActive="True" /> </Grid> </ContentDialog> ``` ```csharp= using System; using Windows.UI.Core; using Windows.UI.Xaml.Controls; // コンテンツ ダイアログの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=234238 を参照してください namespace App8.alte.imple.csv_converter.dialog { public sealed partial class ProgressDialog : ContentDialog { private string m_progress_name = ""; public string ProgressName { get { return m_progress_name; } set { this.m_progress_name = value; } } public ProgressDialog() { this.InitializeComponent(); } public async void InvTitleAsync(string title) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.Title = m_progress_name + " " + title; }); } } } ``` ## 時間がかかる処理を記述 ```csharp= private async void Button_Click(object sender, RoutedEventArgs e) { var progressDialog = new ProgressDialog(); progressDialog.ProgressName = "~処理中..."; var showingDialog = progressDialog.ShowAsync(); await System.Threading.Tasks.Task.Run(() => Process(progressDialog)); showingDialog.Cancel(); progressDialog.Hide(); } private void Process( ProgressDialog progress ) { int count = 0; while (count < 10) { Thread.Sleep(1000); count++; progress.InvTitleAsync(count + " 秒経過..."); } } ``` ###### tags: `UWP` `処理状況ダイアログ` `ProgressRing`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up