From cad81ce7f15b88ff6b3ee3764733aa5d57db31db Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 22 Mar 2024 02:00:04 +0100 Subject: [PATCH] Implement data bindings using `DependencyProperty`s --- Tasks/UrlTester/MainWindow.xaml | 6 ++++-- Tasks/UrlTester/MainWindow.xaml.cs | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Tasks/UrlTester/MainWindow.xaml b/Tasks/UrlTester/MainWindow.xaml index cc75916..5c0e20e 100644 --- a/Tasks/UrlTester/MainWindow.xaml +++ b/Tasks/UrlTester/MainWindow.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:DT3" mc:Ignorable="d" + DataContext="{Binding RelativeSource={RelativeSource Self}}" Title="MainWindow" Height="450" Width="800"> @@ -48,8 +49,8 @@ Value="5"/> - - + + @@ -64,6 +65,7 @@ public partial class MainWindow : Window { + public static readonly DependencyProperty SizeProperty = DependencyProperty.Register( + "Size", + typeof(int), + typeof(MainWindow)); + + public static readonly DependencyProperty TimeProperty = DependencyProperty.Register( + "Time", + typeof(long), + typeof(MainWindow)); + public MainWindow() { InitializeComponent(); @@ -36,9 +46,9 @@ public partial class MainWindow : Window tester.PageLoaded += (_, size) => { stopWatch.Stop(); - bytesBox.Text = $"{size} bytes"; - timeBox.Text = $"{stopWatch.ElapsedMilliseconds} ms"; - timeBar.Value = stopWatch.ElapsedMilliseconds; + SetValue(SizeProperty, size); + SetValue(TimeProperty, stopWatch.ElapsedMilliseconds); + Debug.WriteLine(""); }; _ = tester.GetUrlAsync(urlBox.Text);