wpf中listView多列显示
今天在项目中遇到需要分列显示数据列表,记录一下做法:
代码
1 <ListView BorderThickness="0" Margin="10,0,0,0" Name="myNewListview" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsSource="Myalllresouceist"
2 Width="{Binding (FrameworkElement.ActualWidth),RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
3 ItemContainerStyle="{DynamicResource AllResourceListStyle}" Visibility="{Binding ElementName=listCB, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" >
4 <ListView.ItemsPanel>
5 <ItemsPanelTemplate>
6
7 <WrapPanel ItemWidth="100" ItemHeight="50" IsItemsHost="True" Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"/>
8
9 </ItemsPanelTemplate>
10 </ListView.ItemsPanel>
11
12 </ListView>
2 Width="{Binding (FrameworkElement.ActualWidth),RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
3 ItemContainerStyle="{DynamicResource AllResourceListStyle}" Visibility="{Binding ElementName=listCB, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" >
4 <ListView.ItemsPanel>
5 <ItemsPanelTemplate>
6
7 <WrapPanel ItemWidth="100" ItemHeight="50" IsItemsHost="True" Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"/>
8
9 </ItemsPanelTemplate>
10 </ListView.ItemsPanel>
11
12 </ListView>
style正常写就行
代码
<Style TargetType="ListViewItem" x:Key="AllResourceListStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<StackPanel Orientation="Vertical">
<Button Content="{Binding ElementName}" ToolTip="{Binding ElementName}" Style="{StaticResource LinkButtonSytle}" Width="85" Foreground="#81CAFE" Margin="0,0,2,0" Command="Command:Commands.RunApplicationCommand" CommandParameter="{Binding}"></Button>
<StackPanel Orientation="Horizontal">
<Image Source="{DynamicResource Login13x13}" Width="13" Height="13" VerticalAlignment="Center" Margin="5,0,0,0" />
<Image Source="{DynamicResource OperationPlan10x10}" Width="13" Height="13" VerticalAlignment="Center" Margin="5,0,0,0" />
<Image Source="{DynamicResource Close10x10}" Width="13" Height="13" VerticalAlignment="Center" Margin="5,0,0,0" />
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<StackPanel Orientation="Vertical">
<Button Content="{Binding ElementName}" ToolTip="{Binding ElementName}" Style="{StaticResource LinkButtonSytle}" Width="85" Foreground="#81CAFE" Margin="0,0,2,0" Command="Command:Commands.RunApplicationCommand" CommandParameter="{Binding}"></Button>
<StackPanel Orientation="Horizontal">
<Image Source="{DynamicResource Login13x13}" Width="13" Height="13" VerticalAlignment="Center" Margin="5,0,0,0" />
<Image Source="{DynamicResource OperationPlan10x10}" Width="13" Height="13" VerticalAlignment="Center" Margin="5,0,0,0" />
<Image Source="{DynamicResource Close10x10}" Width="13" Height="13" VerticalAlignment="Center" Margin="5,0,0,0" />
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ok了。