Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to attach a property to an object using XAML
    primarykey
    data
    text
    <p>I'm trying to format my ListBoxItem template to include a image. I can add an image to the ListBoxItem but i'm not too sure on how i would go about setting the value for that image.</p> <p>Template for ListBoxItem:</p> <pre><code> &lt;Style TargetType="{x:Type ListBoxItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ListBoxItem"&gt; &lt;Border Name="Border" Padding="2" SnapsToDevicePixels="true"&gt; &lt;StackPanel Orientation="Horizontal" &gt; &lt;Image Source="{Binding Path=Source}" Height="16" Width="16" HorizontalAlignment="Center" VerticalAlignment="Center" /&gt; &lt;ContentPresenter Name="ContentPresenter" HorizontalAlignment="Stretch" Width="Auto" /&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsSelected" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="{StaticResource ListBoxItem_BackgroundBrush_Selected}"/&gt; &lt;Setter TargetName="ContentPresenter" Property="TextElement.FontWeight" Value="Bold"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="{StaticResource TabItem_BackgroundBrush_Disabled}"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>Example ListBox code:</p> <pre><code> &lt;ListBox Name="listBox_LibAll" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt; &lt;ListBoxItem Content="Item 1" /&gt; &lt;ListBoxItem Content="Item 2" /&gt; &lt;ListBoxItem Content="Item 3" /&gt; &lt;/ListBox&gt; </code></pre> <p>Output: <img src="https://i.stack.imgur.com/lDUt7.png" alt="enter image description here"></p> <p>If you look at the picture you will note that there is a place for the image, i just dont know how to set its value. I was thinking i could somehow attach the "Source" property to the ListBoxItem</p>
    singulars
    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