WPFアプリケーションの画面上にその画面が表示されてからの経過時間をリアルタイムで表示させたいのですが、どうやって実装したらいいかがわかりません。
XAML
1<Window x:Class="Application.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:Application" 7 mc:Ignorable="d" 8 Title="title" Height="450" Width="800"> 9 <Grid> 10 <Label x:Name="Time_Label" Content="{Binding time}" /> 11 </Grid> 12</Window>
C#
1using System; 2using System.Windows; 3using System.Windows.Navigation; 4using System.Diagnostics; 5 6namespace Application 7{ 8 public Stopwatch sw; 9 10 private class BindingData 11 { 12 public string time { get; set; } = "00:00:00.00"; 13 } 14 15 /// <summary> 16 /// MainWindow.xaml の相互作用ロジック 17 /// </summary> 18 public partial class MainWindow : Window 19 { 20 public MainWindow() 21 { 22 InitializeComponent(); 23 sw = new Stopwatch(); 24 sw.Start(); 25 this.DataContext = new BindingData(); 26 } 27 } 28} 29
sw.Elapsed.ToString("hh:mm:ss.ff")を常にリアルタイムでLabelに出力させたいのですが通知のさせ方がよくわかりません。
どなたかご助力をお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/01 00:09