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 - Templating templates?

 
 
Old 10-31-2007   #1 (permalink)
Sorin Dolha


 
 

Templating templates?

Hello,

I am in a situation that, in a custom control I author, I need to generate
some DataTemplate object in a loop, from code, and set them to some
GridViewColumn.CellTemplate values.

All DataTemplate instances will have similar content - by default I use a
StackPanel with two ContentPresenter items - but the difference is made of
the ContentTemplate that I set for one of the two ContentPresenter (as you
one of the ContentPresenter is special), and that ContentTemplate setting is
different for each iteration in my loop.

As you can see the DataTemplate instances I'm generating have very similar
look, but just one property differs for each of them. So I wonder if I could
expose the "template of the template" somehow as XAML, and then allow the
user set it on my control using a property.

I tried to do it by exposing a DataTemplate property like that in my control
(and styling it by default to my default StackPanel and two
ContentPresenters, and the special ContentPresenter's ContentTemplate was
just not set, but instead a special name, i.e. "PART_ContentPresenter" is
set, considering I could find it in runtime), and then I wanted at runtime to
load the DataTemplate and in my loop generate different DataTemplate
instances based on the original DataTemplate, but with the
PART_ContentPresenter.ContentTemplate set to my custom value from the
iteration. But I didn't find a way to do this, and that's why I search for
help here.

I don't know if it's clear what I try to do, but I hope you will understand
that my issue is in fact made of two problems:

1. How to create a copy/clone of a DataTemplate?
2. How to set up one more property to an element in the DataTemplate copy to
a different value? (I tried using LoadContent() and then recursively search
(using VisualTreeHelper.GetChild) for the ContentPresenter, but didn't work -
ContentPresenter was not found in the visual tree.

I understand that I may have reached to a point that shouts: hey, your'e
wrong, you should have done a different design for this feature, but I didn't
want to re-think everything - maybe I can find a way to resolve this in a
good way, with you help.

I thank you in advance for all your comments/suggestions!

--
Sorin Dolha, DlhSoft

My System SpecsSystem Spec
Old 11-04-2007   #2 (permalink)
Sorin Dolha


 
 

RE: Templating templates?

In the meantime I solved my problem by creating a secondary custom control,
that defines a ContentTemplate property of type DataTemplate, and in the
first control in the loop I create templates on the fly by adding the second
custom control type as the visual tree, and set up the ContentTemplate
property to the template in the loop.

--
Sorin Dolha, DlhSoft


"Sorin Dolha" wrote:
Quote:

> Hello,
>
> I am in a situation that, in a custom control I author, I need to generate
> some DataTemplate object in a loop, from code, and set them to some
> GridViewColumn.CellTemplate values.
>
> All DataTemplate instances will have similar content - by default I use a
> StackPanel with two ContentPresenter items - but the difference is made of
> the ContentTemplate that I set for one of the two ContentPresenter (as you
> one of the ContentPresenter is special), and that ContentTemplate setting is
> different for each iteration in my loop.
>
> As you can see the DataTemplate instances I'm generating have very similar
> look, but just one property differs for each of them. So I wonder if I could
> expose the "template of the template" somehow as XAML, and then allow the
> user set it on my control using a property.
>
> I tried to do it by exposing a DataTemplate property like that in my control
> (and styling it by default to my default StackPanel and two
> ContentPresenters, and the special ContentPresenter's ContentTemplate was
> just not set, but instead a special name, i.e. "PART_ContentPresenter" is
> set, considering I could find it in runtime), and then I wanted at runtime to
> load the DataTemplate and in my loop generate different DataTemplate
> instances based on the original DataTemplate, but with the
> PART_ContentPresenter.ContentTemplate set to my custom value from the
> iteration. But I didn't find a way to do this, and that's why I search for
> help here.
>
> I don't know if it's clear what I try to do, but I hope you will understand
> that my issue is in fact made of two problems:
>
> 1. How to create a copy/clone of a DataTemplate?
> 2. How to set up one more property to an element in the DataTemplate copy to
> a different value? (I tried using LoadContent() and then recursively search
> (using VisualTreeHelper.GetChild) for the ContentPresenter, but didn't work -
> ContentPresenter was not found in the visual tree.
>
> I understand that I may have reached to a point that shouts: hey, your'e
> wrong, you should have done a different design for this feature, but I didn't
> want to re-think everything - maybe I can find a way to resolve this in a
> good way, with you help.
>
> I thank you in advance for all your comments/suggestions!
>
> --
> Sorin Dolha, DlhSoft
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Old templates to new Vista General
templates Microsoft Office
Why is the Vista Folder Customization/Templating so FUBAR???? Vista file management
Templates Vista General


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