This is a migrated thread and some comments may be shown as answers.

how to use a common contentcontrol for all controls in wpf

1 Answer 163 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 07 Jun 2013, 08:57 AM
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"
                   x:Key="Sample">
      <StackPanel Orientation="Horizontal">
          <mage x:Name="Symbol"
                         Template="{Binding
                                                          Path=(prop:VResultType),
                                                          RelativeSource={RelativeSource TemplatedParent},
                                                          Converter={StaticResource vSymbolConverter}}"
                         Margin="0,0,5,0"
                         Visibility="Collapsed"
                         Height="16"
                         Width="16">
 
              <ToolTipService.ToolTip>
                  <ToolTip Placement="Bottom"
                           Content="{Binding
                                                      Path=(prop:ResultIndicator.ResultToolTip),
                                                      RelativeSource={RelativeSource TemplatedParent}}" />
              </ToolTipService.ToolTip>
          </uxc:XamlImage>
          <ContentPresenter x:Name="Content"
                            ContentSource="Header"
                            RecognizesAccessKey="True"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            Height="Auto"
                            Width="Auto"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"
                            Visibility="Visible" />
      </StackPanel>
  </ControlTemplate>


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,
Srinivas.
.

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 12 Jun 2013, 07:55 AM
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!




Regards,
Vanya Pavlova
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
General Discussions
Asked by
Ravi
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or