Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.87 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Bind image in templated ListBox to ViewModel property
  2. <Grid.Resources>
  3.             <Style x:Key="ListBoxCheckStyle" TargetType="ListBox">
  4.                 <Setter Property="Template">
  5.                     <Setter.Value>
  6.                         <ControlTemplate TargetType="ListBox">
  7.                             <ItemsPresenter HorizontalAlignment="Left" VerticalAlignment="Top"/>
  8.                         </ControlTemplate>
  9.                     </Setter.Value>
  10.                 </Setter>
  11.             </Style>
  12.             <ItemsPanelTemplate x:Key="ListBoxCheckStyleItemsPanelTemplate">
  13.                 <StackPanel />
  14.             </ItemsPanelTemplate>
  15.             <Style x:Key="ListBoxItemCheckStyle" TargetType="ListBoxItem">
  16.                 <Setter Property="Template">
  17.                     <Setter.Value>
  18.                         <ControlTemplate TargetType="ListBoxItem">
  19.                             <StackPanel Orientation="Horizontal">                                
  20.                                 <ChimeControls:CheckBox
  21.                                         Content="{TemplateBinding Content}"
  22.                                         ContentTemplate="{TemplateBinding ContentTemplate}"
  23.                                         Margin="0,0,10,0"
  24.                                         IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
  25.                                 <Image
  26.                                     Width="16"
  27.                                     Height="16"
  28.                                     VerticalAlignment="Center"
  29.                                     Source="{StaticResource OccurredStatusTypeImageSource}"
  30.                                     Visibility="{Binding HasConsentCondition, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Collapsed}"
  31.                                     HorizontalAlignment="Right"
  32.                                     Margin="10,0,10,0" />
  33.                             </StackPanel>
  34.                         </ControlTemplate>
  35.                     </Setter.Value>
  36.                 </Setter>
  37.             </Style>
  38.         </Grid.Resources>
  39.        
  40. <ListBox
  41.                                 x:Name="objectivesListBox"
  42.                                 HorizontalAlignment="Left"
  43.                                 VerticalAlignment="Top"
  44.                                 Style="{StaticResource ListBoxCheckStyle}"
  45.                                 ItemsPanel="{StaticResource ListBoxCheckStyleItemsPanelTemplate}"
  46.                                 ItemContainerStyle="{StaticResource ListBoxItemCheckStyle}"
  47.                                 ItemsSource="{Binding ObjectivesList}"
  48.                                 DisplayMemberPath="mgt_plan_obj_name"
  49.                                 AttachedProperties:ListBoxSelectedItems.Items="{Binding SelectedObjectives, Mode=TwoWay}"
  50.                                 SelectionMode="Multiple"/>