View Single Post
Old 07-13-2007   #1 (permalink)
Jan Kucera


 
 

Headered custom control

Hi,
so I'm creating a custom control in library, which inherits
HeaderedItemsControl. But I can't manage the default templates to work. I'm
trying something like this:

<Style TargetType="{x:Type src:MyControl}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type src:ConditionBuilderItem}">
<TextBlock Foreground="{TemplateBinding Control.Foreground}"
FontFamily="{TemplateBinding
TextElement.FontFamily}"
FontSize="{TemplateBinding
TextElement.FontSize}"
FontStretch="{TemplateBinding
TextElement.FontStretch}"
FontStyle="{TemplateBinding
TextElement.FontStyle}"
FontWeight="{TemplateBinding
TextElement.FontWeight}"
HorizontalAlignment="{TemplateBinding
Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding
Control.VerticalContentAlignment}">
<TextBlock.Text>
<Binding Source="{TemplateBinding Header}" />
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type src:ConditionBuilderItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding
BorderThickness}"
SnapsToDevicePixels="{TemplateBinding
SnapsToDevicePixels}">
<ContentPresenter
Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding
HeaderTemplate}"
ContentSource="Header"
HorizontalAlignment="{TemplateBinding
HorizontalContentAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

But this does not work. From the HeaderTemplate, I cannot access MyControl,
since TemplateBinding is working with ContentProsenter. Morever, I have a
bad feeling of this piece of XAML, I don't think it should be done this way,
should it? Is there any reference available for creating Headered custom
controls?

Thank you,
Jan


My System SpecsSystem Spec