-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathMainWindow.xaml
90 lines (81 loc) · 4.53 KB
/
MainWindow.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<Window x:Class="ListViewSample.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:local="clr-namespace:ListViewSample"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="525"
Height="350"
d:DataContext="{d:DesignInstance local:MainViewModel}"
mc:Ignorable="d">
<Window.Resources>
<ResourceDictionary>
<local:EnumToBoolConverter x:Key="EnumToBoolConverter" />
<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
<Style TargetType="{x:Type ListView}">
<Style.Resources>
<!-- this is necessary to prevent nasty can not find stuff like -->
<!-- ItemsPanel Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ListViewItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') -->
<Style BasedOn="{StaticResource ListViewItemStyle}" TargetType="{x:Type ListViewItem}" />
</Style.Resources>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItemStyle}" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Center"
Text="{Binding}" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Style.Triggers>
<DataTrigger Binding="{Binding ListViewMode, Mode=OneWay}"
Value="{x:Static local:ListViewMode.Tile}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid Width="40" Height="40">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding}" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="5 0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
Margin="0 5"
HorizontalAlignment="Right"
Orientation="Horizontal">
<RadioButton Margin="1"
Content="Standard"
IsChecked="{Binding ListViewMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static local:ListViewMode.Standard}}" />
<RadioButton Margin="1"
Content="Tile"
IsChecked="{Binding ListViewMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static local:ListViewMode.Tile}}" />
</StackPanel>
<ListView Grid.Row="1" ItemsSource="{Binding SimpleItems}" />
</Grid>
</Window>