1 Replies - 8950 Views - Last Post: 02 January 2013 - 06:39 PM Rate Topic: -----

#1 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • View blog
  • Posts: 552
  • Joined: 07-July 10

Apply Named Template to every Control on UserControl

Posted 31 December 2012 - 12:39 PM

I have named Styles and Templates in my App.xaml file. I can apply these to each control throughout my project. I have a UserControl with X number of Buttons. Instead of specifying each Button's style, I was able to use BasedOn:
<UserControl ...>
   <UserControl.Resources>
      <Style TargetType={x:Type Button}" BasedOn="{StaticResource styBigButtons}">
         <Setter Property="Margin" Value="10" />
      </Style>
   </UserControl.Resources>
<Grid>
   ///This is a very condensed example so we can get to the point
   <Button Name="btn1" Content="1" Template="{StaticResource ctRedButton}" />
   ...
   <Button Name="btn9" Content="9" Template="{StaticResource ctRedButton}" />
</Grid>
</UserControl>


This has saved a lot of typing to specify which style to use on this page. Is there a way to set all Buttons' Templates on this page using a named Template I already have? It would make sense for this to be possible.

Is This A Good Question/Topic? 0
  • +

Replies To: Apply Named Template to every Control on UserControl

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1067
  • View blog
  • Posts: 4,174
  • Joined: 02-July 08

Re: Apply Named Template to every Control on UserControl

Posted 02 January 2013 - 06:39 PM

Just a little way down the forum was my topic!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1