-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverTutorial.xaml
60 lines (54 loc) · 2.66 KB
/
converTutorial.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
<Window x:Class="ValueConverters.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ValueConverters"
xmlns:converters="clr-namespace:ValueConverters.Converters"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibility"/>
<converters:BoolToBrushConverter x:Key="StatusToBrush"/>
<converters:BoolToStringConverter x:Key="BoolToString"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!-- Example 1 -->
<StackPanel Grid.Column="0" Grid.Row="0" Margin="5">
<CheckBox x:Name="visibleCheck" IsChecked="True" Content="Is Visible"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" Margin="5">
<Button Content="I am visible!" Visibility="{Binding ElementName=visibleCheck,
Path=IsChecked,
Converter={StaticResource BoolToVisibility}}"/>
</StackPanel>
<!-- Example 2 -->
<StackPanel Grid.Column="0" Grid.Row="1" Margin="5">
<CheckBox x:Name="onlineCheck" Content="Is Online"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="1" Margin="5">
<Label Content="FrogPattle13" Foreground="{Binding ElementName=onlineCheck,
Path=IsChecked,
Converter={StaticResource StatusToBrush}}"/>
</StackPanel>
<!-- Example 3 -->
<StackPanel Grid.Column="0" Grid.Row="2" Margin="5">
<CheckBox x:Name="newsCheck" Content="Signup for Newsletter"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="2" Margin="5">
<Label>Signed up for newsletter</Label>
<TextBox Text="{Binding ElementName=newsCheck,
Path=IsChecked,
Converter={StaticResource BoolToString}}"/>
</StackPanel>
</Grid>
</Window>