Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista Tutorial - Headered custom control

 
 
Old 07-13-2007   #1 (permalink)
Jan Kucera
Guest


 
 

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
Old 07-14-2007   #2 (permalink)
Lloyd Dupont
Guest


 
 

Re: Headered custom control

I haven't look at your XAML, but I have an advice, take a look at the XAML
of the default controls (it really helps)!!

For that you should download Reflector and the BAML reader plugin, if you
haven't done it already.
Then use the BAML reader on PresentationFramework.aero.dll

"Jan Kucera" <miloush@community.nospam> wrote in message
news:9E6EC046-C164-4BDA-9937-413DF9E951D4@microsoft.com...
> 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
Old 07-15-2007   #3 (permalink)
Jan Kucera
Guest


 
 

Re: Headered custom control

Hi Lloyd, thank you for the tip with BAML reader. The problem is that none
of the built-in headered controls has a template for header.
But I will probably go the same way...
In the code I posted, btw, seems to be error in using TemplateBinding inside
DataTemplate.

Jan

"Lloyd Dupont" <net.galador@ld> wrote in message
news:#eB0z#mxHHA.484@TK2MSFTNGP06.phx.gbl...
>I haven't look at your XAML, but I have an advice, take a look at the XAML
>of the default controls (it really helps)!!
>
> For that you should download Reflector and the BAML reader plugin, if you
> haven't done it already.
> Then use the BAML reader on PresentationFramework.aero.dll
>
> "Jan Kucera" <miloush@community.nospam> wrote in message
> news:9E6EC046-C164-4BDA-9937-413DF9E951D4@microsoft.com...
>> 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
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46