[WPF MVVM] ListBox File Explorer XAML Style

 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
<Style x:Key="DatabaseFileList" TargetType="{x:Type ListBox}">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<WrapPanel IsItemsHost="True" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Setters>
<Setter Property="Foreground" Value="SteelBlue" />
<Setter Property="BorderBrush" Value="CornflowerBlue" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="9,2,2,2" />
<Setter Property="Height" Value="30"/>
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="CornflowerBlue" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Button.Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type secondaryModels:DatabaseFile}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="170"/>
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Fill="{Binding FileExt, Converter={StaticResource ExtensionToIconConverter}, Mode=OneWay}"/>
<StackPanel x:Name="FileInf" Grid.Column="1" Margin="8,0,8,0" Orientation="Vertical">
<TextBlock Margin="0,-2,0,0" Text="{Binding FileName}" />
<TextBlock FontSize="12" FontWeight="Light" Text="{Binding FileSize, StringFormat={}{0:n2} мб}" />
</StackPanel>
<Button Grid.Column="2"
Name="DeleteFileButton"
Content="Удалить"
Margin="0,1,1,1"
Padding="10,0,10,0"
Command="{Binding Path=DataContext.DeleteFileCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type catel:DataWindow}}}"
CommandParameter="{Binding}">
</Button>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>