Caliburn Micro下轻松实现ListView的全选功能

Caliburn Micro是一个Caliburn精简版的开源框架,基于MVVM模式,可用于WPF, Silverlight, WP7等。有关它的具体介绍请看:

http://caliburnmicro.codeplex.com/

 

下面主要使用CM(Caliburn Micro)实现WPF的ListView全选功能,直接上码:

 1 <ListView Name= " lvFileCart " DockPanel.Dock= " Top " ItemsSource= " {Binding FileCart} " FontSize= " 12 " Height= " 150 ">
 2                 <ListView.ItemContainerStyle>
 3                     <Style TargetType= " ListViewItem ">
 4                         <Setter Property= " HorizontalContentAlignment " Value= " Stretch " />
 5                         <Setter Property= " IsSelected " Value= " {Binding IsSelected, Mode=TwoWay} "/>
 6                     </Style>
 7                 </ListView.ItemContainerStyle>
 8                 <ListView.View>
 9                     <GridView>
10                         <GridViewColumn Width= " 50 ">
11                             <GridViewColumn.CellTemplate>
12                                  <DataTemplate>
13                                      <CheckBox IsChecked= " {Binding IsSelected,RelativeSource={RelativeSource AncestorType=ListViewItem}} "  HorizontalAlignment= " Center " />
14                                  </DataTemplate>
15                             </GridViewColumn.CellTemplate>
16                              <HeaderedItemsControl>
17                                  <CheckBox cal:Action.Target= " {Binding ElementName=lvFileCart} " 
18                                            cal:Message.Attach= " [Event Checked]=[Action SelectAll]; [Event Unchecked]=[Action UnselectAll] "  />
19                              </HeaderedItemsControl>
20                         </GridViewColumn>
21                         <GridViewColumn Width= " 200 " Header= " Name " DisplayMemberBinding= " {Binding Path=FileName} "/>
22                         <GridViewColumn Width= " 100 " Header= " Size " DisplayMemberBinding= " {Binding Path=FileSize} "/>
23                         <GridViewColumn Width= " 200 " Header= " Path " DisplayMemberBinding= " {Binding Path=FilePath} "/>
24                     </GridView>
25                 </ListView.View>
26             </ListView>

 结果如下:

Caliburn Micro下轻松实现ListView的全选功能

Caliburn Micro下轻松实现ListView的全选功能

 

你可能感兴趣的:(ListView)