我正在尝试复制Windows资源管理器中的功能,以通过一系列布局切换按钮更改布局。布局,如“列表”,“详细信息”,“瓷砖”等等。
我已经找到了其他几个帖子,但没有一个真的为我解答了问题,而且他们都是C#而且我没有使用C#所以试图破译答案非常令人沮丧。
这就是我到目前为止所做的事情 - 我在尝试开始工作的同时开始只使用List和Details,但也计划添加Tiles和Content:
XAML:
<Window.Resources>
<DataTemplate x:Key="List_Template">
<Grid...>
</DataTemplate>
<DataTemplate x:Key="Details_Template">
<Grid...>
</DataTemplate>
<DataTemplate x:Key="SelectedItem_Template">
<Grid...>
</DataTemplate>
<Style TargetType="{x:Type ListBoxItem}" x:Key="List_ContainerStyle">
<Setter Property="ContentTemplate" Value="{StaticResource List_Template}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SelectedItem_Template}" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ListBoxItem}" x:Key="Details_ContainerStyle">
<Setter Property="ContentTemplate" Value="{StaticResource Details_Template}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SelectedItem_Template}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
我现在使用单选按钮来更改布局以简化,但在某些时候会将它们更改为类似于Windows资源管理器选项的按钮:
<Grid Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="List_RadioButton" Content="List" Grid.Row="0" Grid.Column="0" Margin="8,0,8,0" VerticalAlignment="Center"
Foreground="{DynamicResource LightFont_Colour}"
IsChecked="True"/>
<RadioButton x:Name="Details_RadioButton" Content="Details" Grid.Row="0" Grid.Column="1" Margin="8,0,8,0" VerticalAlignment="Center"
Foreground="{DynamicResource LightFont_Colour}"
IsChecked="False"/>
</Grid>
ListView是数据绑定到SQL Server的视图。默认情况下,如果不是由用户手动设置,我希望它在列表布局上:
<Grid x:Name="Grid_Body" Grid.Row="3" Grid.ColumnSpan="2" >
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<ListView x:Name="DataList_ListView"
Grid.Row="0" SelectionMode="Single" SelectedValuePath="ID"
IsSynchronizedWithCurrentItem="True"
DataContext="{Binding}"
ItemContainerStyle="{StaticResource List_ContainerStyle}"
Background="{DynamicResource WhiteBackground_90Transparent}" Margin="0,0,0,0">
</ListView>
</Grid>
VB.NET - 当我点击RadioButton更改为详细信息布局或返回列表布局时,我一直在尝试找到一种方法来更改代码中的ItemContainerStyle。以下不起作用,部分取消了另一个stackoverflow帖子:
Private Sub List_RadioButton_Checked(sender As Object, e As RoutedEventArgs) Handles List_RadioButton.Checked
CaseList_ListView.ItemContainerStyle = DirectCast(Resources("List_ContainerStyle"), System.Windows.Style)
End Sub
Private Sub Details_RadioButton_Checked(sender As Object, e As RoutedEventArgs) Handles Details_RadioButton.Checked
CaseList_ListView.ItemContainerStyle = DirectCast(Resources("Details_ContainerStyle"), System.Windows.Style)
End Sub
任何帮助都将不胜感激。