-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainWindowOnlyXaml.xaml
76 lines (56 loc) · 3.28 KB
/
MainWindowOnlyXaml.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<Window x:Class="TddForWpf.MainWindowOnlyXaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tdd="clr-namespace:TddForWpf"
Title="MainWindowOnlyXaml" WindowStartupLocation="CenterScreen">
<!-- Не для тестирования! Только для демонстрации работы с ресурсами. -->
<Window.Resources>
<!-- Экземпляр команды -->
<RoutedCommand x:Key="Calculate" />
<!-- Экземпляр калькулятора -->
<tdd:Calculator x:Key="Calculator" />
<!-- Экземпляр модели калькулятора -->
<!-- Numbers="1,2,3" - установка данных -->
<!-- Calculator="{StaticResource Calculator}" - ссылка на экземпляр калькулятора -->
<tdd:CalculatorViewModel x:Key="View" Numbers="1,2,3" Сalculator="{StaticResource Calculator}" />
</Window.Resources>
<Window.CommandBindings>
<!-- Подписываем окно на обработку команды Calculate. -->
<!-- Подключаем метод обработки команды CalculateExecuted. -->
<CommandBinding Command="{StaticResource Calculate}" Executed="CalculateExecuted" />
</Window.CommandBindings>
<!-- Установка контекста формы. Ссылка на модель в ресурсах. -->
<Window.DataContext>
<Binding Source="{StaticResource View}"/>
</Window.DataContext>
<!-- Установка контекста формы. Создание нового экземпляра модели. Что бы использовать это вариант, необходимо закомментировать верхний. -->
<!--
<Window.DataContext>
<tdd:CalculatorViewModel Numbers="1,2,3">
<tdd:CalculatorViewModel.Calculator>
<tdd:Calculator />
</tdd:CalculatorViewModel.Calculator>
</tdd:CalculatorViewModel>
</Window.DataContext>
-->
<Grid Margin="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="3" Text="Numbers:" />
<TextBox Grid.Row="0" Grid.Column="1" Margin="3" Name="NumbersTextBox"
Text="{Binding Path=Numbers, Mode=OneWayToSource}" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="3" Text="Result:" />
<TextBox Grid.Row="1" Grid.Column="1" Margin="3" IsReadOnly="True" Name="ResultTextBox"
Text="{Binding Path=Result, Mode=OneWay}" />
<Button Grid.Row="3" Grid.Column="1" Margin="3" Padding="3" Content="Calculate" Name="CalculateButton"
Command="{StaticResource Calculate}" />
</Grid>
</Window>