Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you were almost there.</p> <pre><code>Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } public class ImageItem: DependencyObject { public static readonly DependencyProperty SourceProperty = DependencyProperty.RegisterAttached("Source", typeof(string), typeof(DependencyObject), new PropertyMetadata((o, e) =&gt; { //System.Diagnostics.Debugger.Break(); })); public static string GetSource(DependencyObject o) { return (string)o.GetValue(ImageItem.SourceProperty); } public static void SetSource(DependencyObject o, string e) { o.SetValue(ImageItem.SourceProperty, e); } } } </code></pre> <p>Markup:</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid&gt; &lt;Grid.Resources&gt; &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, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" 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; &lt;/Grid.Resources&gt; &lt;ListBox Name="listBox_LibAll" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt; &lt;ListBoxItem local:ImageItem.Source="/WpfApplication1;component/Penguins.jpg" Content="Item 1" /&gt; &lt;ListBoxItem Content="Item 2" /&gt; &lt;ListBoxItem Content="Item 3" /&gt; &lt;/ListBox&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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