Question

I am developing a custom control derived from System.Windows.Controls.ContentControl. In the controls default template (themes\generic.xaml), I use a Border element that wraps the actual content.

Does my custom control already implement margin and padding (i.e., shrink the border according to the padding set on the custom control) or do/can I decide myself, where margin and padding are applied (i.e., set the margin and padding properties on the border element to {TemplateBinding Margin} etc.

Thanks in advance!

Was it helpful?

Solution

Margin is implemented I believe all the way down in Framework element. However Padding is not. ContentControl has the "PaddingProperty" but by default it doesn't do anything. Basically you bind the MarginProperty of the Content to the Padding property of the content control.

OTHER TIPS

I solved the problem by defining a style for ContentControl and binding the Padding to Margin of the ContentPresenter defined in the template.

<Style TargetType="{x:Type ContentControl}">
     <Setter Property="Template">
          <Setter.Value>
               <ControlTemplate TargetType="{x:Type ContentControl}">                          
                    <ContentPresenter Margin="{TemplateBinding Padding}"/>                                
               </ControlTemplate>
          </Setter.Value>
     </Setter>
</Style>

Maybe this helps others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top