Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Templates and Custom Classes [modified]

Templates and Custom Classes [modified]

Scheduled Pinned Locked Moved WCF and WF
wpfcssquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR Offline
    realJSOPR Offline
    realJSOP
    wrote on last edited by
    #1

    Okay, I've scraped a template from a 3rd party control (the Telerik RadGridView if you must know), and I've managed to add a titlebar and an export button to the template (in the XAML). It looks like this:

    <Style x:Key="MyGridStyle">
    <Border x:Name="PART_TitleBar" Grid.Row="0" BorderBrush="Black" Background="Black"
    BorderThickness="1" Height="28">
    <Grid>
    <Label x:Name="PART_Title" Content="Title" FontWeight="Bold" FontStyle="Italic"
    VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
    Foreground="White" Background="Transparent" IsTabStop="False"/>
    <Button x:Name="buttonExport" Content="Export" Width="75" HorizontalAlignment="Right"
    VerticalAlignment="Top" Margin="0,2.5,3,0"/>
    </Grid>
    </Border>

    ...
    ...

    <Style x:Key="MyGridStyle">

    Now, I want to be able to modify the properties of these two new template items in the controls that use this style. Do I need to write CS code to do this, or can I do it all in the XAML of the element that uses that style?

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    modified on Thursday, June 25, 2009 9:42 AM

    A M 2 Replies Last reply
    0
    • realJSOPR realJSOP

      Okay, I've scraped a template from a 3rd party control (the Telerik RadGridView if you must know), and I've managed to add a titlebar and an export button to the template (in the XAML). It looks like this:

      <Style x:Key="MyGridStyle">
      <Border x:Name="PART_TitleBar" Grid.Row="0" BorderBrush="Black" Background="Black"
      BorderThickness="1" Height="28">
      <Grid>
      <Label x:Name="PART_Title" Content="Title" FontWeight="Bold" FontStyle="Italic"
      VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
      Foreground="White" Background="Transparent" IsTabStop="False"/>
      <Button x:Name="buttonExport" Content="Export" Width="75" HorizontalAlignment="Right"
      VerticalAlignment="Top" Margin="0,2.5,3,0"/>
      </Grid>
      </Border>

      ...
      ...

      <Style x:Key="MyGridStyle">

      Now, I want to be able to modify the properties of these two new template items in the controls that use this style. Do I need to write CS code to do this, or can I do it all in the XAML of the element that uses that style?

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      modified on Thursday, June 25, 2009 9:42 AM

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      If it answer's your question - Style Triggers[^] ?

      realJSOPR 1 Reply Last reply
      0
      • A ABitSmart

        If it answer's your question - Style Triggers[^] ?

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        No, I don't think that's what I want. Given the template code provided in the OP, I want to be able to *override* certain properties of the new parts without having to completely replace the template in XAML. For instance, I may want to change the background color of the border or the color or font of the label text, or I may want to make the button invisible.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        1 Reply Last reply
        0
        • realJSOPR realJSOP

          Okay, I've scraped a template from a 3rd party control (the Telerik RadGridView if you must know), and I've managed to add a titlebar and an export button to the template (in the XAML). It looks like this:

          <Style x:Key="MyGridStyle">
          <Border x:Name="PART_TitleBar" Grid.Row="0" BorderBrush="Black" Background="Black"
          BorderThickness="1" Height="28">
          <Grid>
          <Label x:Name="PART_Title" Content="Title" FontWeight="Bold" FontStyle="Italic"
          VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
          Foreground="White" Background="Transparent" IsTabStop="False"/>
          <Button x:Name="buttonExport" Content="Export" Width="75" HorizontalAlignment="Right"
          VerticalAlignment="Top" Margin="0,2.5,3,0"/>
          </Grid>
          </Border>

          ...
          ...

          <Style x:Key="MyGridStyle">

          Now, I want to be able to modify the properties of these two new template items in the controls that use this style. Do I need to write CS code to do this, or can I do it all in the XAML of the element that uses that style?

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          modified on Thursday, June 25, 2009 9:42 AM

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          It's the same as with any other element - if there's properties that can be set on the element then you can override them in XAML where you use the control. It's up to you to design the element and the template if you need access to properties down the tree in the control. TemplateBinding is your friend here. Pretty much none of the properties you've shown in your template are overridable.

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          realJSOPR 1 Reply Last reply
          0
          • M Mark Salsbery

            It's the same as with any other element - if there's properties that can be set on the element then you can override them in XAML where you use the control. It's up to you to design the element and the template if you need access to properties down the tree in the control. TemplateBinding is your friend here. Pretty much none of the properties you've shown in your template are overridable.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            This is what I've done. In the code below, I've only included one attached property since I figure that should serve as enough of an example of what I'm doing. First, I have my custom control class:

            public class UDPTelerikGridView: RadGridView
            {
            static UDPTelerikGridView()
            {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(UDPTelerikGridView),
            new FrameworkPropertyMetadata(typeof(UDPTelerikGridView)));
            }

            //--------------------------------------------------------------------------------
            public static readonly DependencyProperty TitleBarVisibilityProperty = 
            		   DependencyProperty.RegisterAttached("TitleBarVisibility", 
            			                               typeof(Visibility), 
            						       typeof(UDPTelerikGridView));
            
            public static void SetTitleBarVisibility(UIElement element, Visibility value)
            {
            	element.SetValue(TitleBarVisibilityProperty, value);
            }
            
            public static Visibility GetTitleBarVisibility(UIElement element)
            {
            	return (Visibility)element.GetValue(TitleBarVisibilityProperty);
            }
            
            //--------------------------------------------------------------------------------
            public override void OnApplyTemplate()
            {
            	base.ApplyTemplate();
            
            	Border titleBar = base.GetTemplateChild("PART\_TitleBar") as Border;
            	if (titleBar != null)
            	{
            		titleBar.Visibility      = GetTitleBarVisibility(titleBar);
            	}
            }
            

            }

            Next, I have the Style I wrote to include the new components as part of the existing RadGridView control (all of the original template that follows my additional stuff is omitted in the interest of brevity:

            <Style x:Key="UDPRadGridViewTopTitle" TargetType="{x:Type udpcontrols:UDPTelerikGridView}">
            <Setter Property="Template">
            <Setter.Value>
            <ControlTemplate TargetType="{x:Type telerik:RadGridView}">
            <AdornerDecorator>
            <Border x:Name="PART_MasterGridContainer">
            <Grid>
            <Grid.RowDefinitions>
            <RowDefinition Height="28" />
            <RowDefinition />
            </Grid.RowDefinitions>
            <Border x:Name="PART_TitleBar" Grid.Row="0"
            BorderBrush="{TemplateBinding BorderBrush}"
            Background="{TemplateBinding Background}"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups