Blog Archive

Monday, May 19, 2008

Use Style to Add Control Template

WPF make is very easy to do "owner-drawl" by Control Template

<Window.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<DockPanel>
<TextBlock TextTrimming="CharacterEllipsis" Width="150" Text="{TemplateBinding Content}" Foreground="Red"/>
<Image Source="c:\working\Test1.jpg" Width="20" Height="20"/>
<DockPanel> </ControlTemplate> </Setter.Value>
</Setter>
</Style>
</Window.Resources> <StackPanel Margin="30">
<ListBox>
<ListBoxItem>Test this /ListBoxItem>
</ListBox>
</StackPanel>

No comments: