Note that there are some explanatory texts on larger screens.

plurals
  1. POBind image in templated ListBox to ViewModel property
    primarykey
    data
    text
    <p>TL;DR - I had a binding error. Tired eyes miss things.</p> <p>I have implemented a multi-select CheckBox list using a ListBox as the container. Now, beside each checkbox in the list I want to display an image whose visbility is bound to a ViewModel property, but I'm having difficulty doing this.</p> <p>My styles are:</p> <pre><code>&lt;Grid.Resources&gt; &lt;Style x:Key="ListBoxCheckStyle" TargetType="ListBox"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ListBox"&gt; &lt;ItemsPresenter HorizontalAlignment="Left" VerticalAlignment="Top"/&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;ItemsPanelTemplate x:Key="ListBoxCheckStyleItemsPanelTemplate"&gt; &lt;StackPanel /&gt; &lt;/ItemsPanelTemplate&gt; &lt;Style x:Key="ListBoxItemCheckStyle" TargetType="ListBoxItem"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ListBoxItem"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;ChimeControls:CheckBox Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="0,0,10,0" IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/&gt; &lt;Image Width="16" Height="16" VerticalAlignment="Center" Source="{StaticResource OccurredStatusTypeImageSource}" Visibility="{Binding HasConsentCondition, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Collapsed}" HorizontalAlignment="Right" Margin="10,0,10,0" /&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Grid.Resources&gt; </code></pre> <p>My Listbox is defined as:</p> <pre><code>&lt;ListBox x:Name="objectivesListBox" HorizontalAlignment="Left" VerticalAlignment="Top" Style="{StaticResource ListBoxCheckStyle}" ItemsPanel="{StaticResource ListBoxCheckStyleItemsPanelTemplate}" ItemContainerStyle="{StaticResource ListBoxItemCheckStyle}" ItemsSource="{Binding ObjectivesList}" DisplayMemberPath="mgt_plan_obj_name" AttachedProperties:ListBoxSelectedItems.Items="{Binding SelectedObjectives, Mode=TwoWay}" SelectionMode="Multiple"/&gt; </code></pre> <p>My image never displays though, and the getter of the property the Visibility is bound to is never called. What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload