how to use a common contentcontrol for all controls in wpf

2 posts, 0 answers
  1. Ravi
    Ravi avatar
    97 posts
    Member since:
    Jun 2012

    Posted 07 Jun 2013 Link to this post

    Hi There,

    I have a requirement where i have to display a small image at left side of contentpresenter on every header of control. for this at present i have to add a below xaml to every controls template,

    <ControlTemplate TargetType="ContentControl"
          <StackPanel Orientation="Horizontal">
              <mage x:Name="Symbol"
                                                              RelativeSource={RelativeSource TemplatedParent},
                                                              Converter={StaticResource vSymbolConverter}}"
                      <ToolTip Placement="Bottom"
                                                          RelativeSource={RelativeSource TemplatedParent}}" />
              <ContentPresenter x:Name="Content"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                Visibility="Visible" />

    but there will be a huge maintenance. i want to place this in one place may be i can create a template for contentpresenter and i can use the style key. 

    If you have any better solution please guide me.

    Thanks in Advance,
  2. Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 12 Jun 2013 Link to this post

    Hi Srinivas,

    Most components with headers expose a property such as Header/HeaderTemplate, which you can use to
    set your headers with the desired style explicitly. I do not recommend you to define an implicit style targeted at ContentControl with the corresponding template since it will be applied not only to the headers, but to the parts of the templates of this type as well.  You may place your style targeted at this element at a central place (let's say App.xaml) and set it to per control level in order to ensure that it will be applied to the desired elements. 
    Hope this helps!

    Vanya Pavlova

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top