I have a ListView that uses a template to display a check box. I can not figure out how to get it to databind to the MapName property. Any help would be greatly appreciated. Is there anyway to sort the ListView on if the checkbox is checked?
<Window.Resources>
<ControlTemplate x:Key="ItemTemplate" TargetType="ListViewItem">
<Border
BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
SnapsToDevicePixels="True"
>
<ContentPresenter
Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
/>
</Border>
</ControlTemplate>
<Style TargetType="ListViewItem">
<Setter Property="Template" Value="{StaticResource ItemTemplate}" />
</Style>
<DataTemplate x:Key="ItemDataTemplate">
<CheckBox
x:Name="checkbox"
Content="{Binding}"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}"
Foreground="{DynamicResource WhiteToLightGrayFlatBrush}"
/>
</DataTemplate>
</Window.Resources>
<Border Grid.Row="7" BorderThickness="0,1,0,0" Margin="0,0,0,0" Padding="1,3,3,3"
BorderBrush="{DynamicResource GrayBorderBrush}" >
<StackPanel Orientation="Vertical">
<Label HorizontalAlignment="Left"
Content="Selected Maps:"
Foreground="{DynamicResource WhiteToLightGrayFlatBrush}"
Style="{StaticResource LabelDefaultTransparentBkgr}" />
<ListView
x:Name="mListView"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Background="Transparent"
SelectionMode="Multiple"
MinHeight="73"
MaxHeight="73"
ItemTemplate="{StaticResource ItemDataTemplate}"/>
</StackPanel>
</Border>
Thanks!
Dave
Provided the
ListView.ItemsSource
is bound to collection of objects withMapName
property, just settingContent="{Binding MapName}"
in yourDataTemplate
won't work?Sorting can be implemented easily as described here.