Implement data bindings using DependencyProperty
s
This commit is contained in:
parent
08f6288f91
commit
cad81ce7f1
2 changed files with 17 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:DT3"
|
xmlns:local="clr-namespace:DT3"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding RelativeSource={RelativeSource Self}}"
|
||||||
Title="MainWindow"
|
Title="MainWindow"
|
||||||
Height="450"
|
Height="450"
|
||||||
Width="800">
|
Width="800">
|
||||||
|
@ -48,8 +49,8 @@
|
||||||
Value="5"/>
|
Value="5"/>
|
||||||
</Style>
|
</Style>
|
||||||
</StackPanel.Resources>
|
</StackPanel.Resources>
|
||||||
<TextBlock x:Name="bytesBox" />
|
<TextBlock Text="{Binding Size, StringFormat={}{0} bytes}" />
|
||||||
<TextBlock x:Name="timeBox" />
|
<TextBlock Text="{Binding Time, StringFormat={}{0} ms}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
@ -64,6 +65,7 @@
|
||||||
<ProgressBar x:Name="timeBar"
|
<ProgressBar x:Name="timeBar"
|
||||||
Minimum="0"
|
Minimum="0"
|
||||||
Maximum="1000"
|
Maximum="1000"
|
||||||
|
Value="{Binding Time}"
|
||||||
Grid.ColumnSpan="3" />
|
Grid.ColumnSpan="3" />
|
||||||
<TextBlock Grid.Row="1"
|
<TextBlock Grid.Row="1"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
|
|
|
@ -18,6 +18,16 @@ namespace UrlTester;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
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()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -36,9 +46,9 @@ public partial class MainWindow : Window
|
||||||
tester.PageLoaded += (_, size) =>
|
tester.PageLoaded += (_, size) =>
|
||||||
{
|
{
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
bytesBox.Text = $"{size} bytes";
|
SetValue(SizeProperty, size);
|
||||||
timeBox.Text = $"{stopWatch.ElapsedMilliseconds} ms";
|
SetValue(TimeProperty, stopWatch.ElapsedMilliseconds);
|
||||||
timeBar.Value = stopWatch.ElapsedMilliseconds;
|
Debug.WriteLine("");
|
||||||
};
|
};
|
||||||
|
|
||||||
_ = tester.GetUrlAsync(urlBox.Text);
|
_ = tester.GetUrlAsync(urlBox.Text);
|
||||||
|
|
Loading…
Reference in a new issue