![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| Thread Tools | |
| |