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 - Supplying named content as a parameter to control template.

 
 
Old 01-31-2006   #1 (permalink)
Griff


 
 

Supplying named content as a parameter to control template.

I'd like in my main markup to specify a control template by name as one of my
parameters.
That is to say, my App resources will have a load of different vector
graphics pictures and I want to choose one as a parameter to use on my
control when I add a control to my markup.

So in the markup I call my button class that inherits from Button.

<local:myButton x:Name="button1"
Content="{StaticResource myPicture1}"
Style="{StaticResource myButtonStyle}" />

and in the applications resources I have

<Style x:Key="myButtonStyle" TargetType="{x:Type local:myButton}">
<Setter Property="Template" Value="{StaticResource myButtonTemplate}" />
</Style>

<ControlTemplate x:Key="myButtonTemplate" TargetType="{x:Type
local:myButton}">
<Grid>
<ContentPresenter Grid.Row="0" Content="{TemplateBinding
Property=Content}"/>
</Grid>
</ControlTemplate>


<ControlTemplate x:Key="myPicture1">
some graphical elements
</ControlTemplate>

<ControlTemplate x:Key="myPicture2">
completely different set of graphical elements
</ControlTemplate>

etc


As I've written it does not work.
I'm not sure if I'm just missing some syntax or if the approach is
fundamentally doomed. I'd really prefer not to have to do this in code.


--
Griff
(trying to make an industrial UI with XAML/WPF/c#)

My System SpecsSystem Spec
Old 01-31-2006   #2 (permalink)
Griff


 
 

RE: Supplying named content as a parameter to control template.

Have found out how to do this.

I supply the content in the main markup with

<local:myControl
param1="{StaticResource myPicture1}"
Style ="{StaticResource myStyle }" />

Then in the Control Temnplate called up by the Style I dusplay the content
with

<Control Template="{TemplateBinding Property=param1}"/>

Which seems obvious with hindsight...


--
Griff
(trying to make an industrial UI with XAML/WPF/c#)


"Griff" wrote:

> I'd like in my main markup to specify a control template by name as one of my
> parameters.
> That is to say, my App resources will have a load of different vector
> graphics pictures and I want to choose one as a parameter to use on my
> control when I add a control to my markup.
>
> So in the markup I call my button class that inherits from Button.
>
> <local:myButton x:Name="button1"
> Content="{StaticResource myPicture1}"
> Style="{StaticResource myButtonStyle}" />
>
> and in the applications resources I have
>
> <Style x:Key="myButtonStyle" TargetType="{x:Type local:myButton}">
> <Setter Property="Template" Value="{StaticResource myButtonTemplate}" />
> </Style>
>
> <ControlTemplate x:Key="myButtonTemplate" TargetType="{x:Type
> local:myButton}">
> <Grid>
> <ContentPresenter Grid.Row="0" Content="{TemplateBinding
> Property=Content}"/>
> </Grid>
> </ControlTemplate>
>
>
> <ControlTemplate x:Key="myPicture1">
> some graphical elements
> </ControlTemplate>
>
> <ControlTemplate x:Key="myPicture2">
> completely different set of graphical elements
> </ControlTemplate>
>
> etc
>
>
> As I've written it does not work.
> I'm not sure if I'm just missing some syntax or if the approach is
> fundamentally doomed. I'd really prefer not to have to do this in code.
>
>
> --
> Griff
> (trying to make an industrial UI with XAML/WPF/c#)

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
TFS 2008 Process Template: Default value tag for work item fieldsdoes not allow more than 255 characters to be entered into an HTML control .NET General
How to best control parameter attributes and parameter parsing in your own scripts? PowerShell


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