Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In my app.xaml, I have (beside other styles) the following:
XML
<Style x:Key="BasicStyle">
  <Setter Property="FrameworkElement.Margin" Value="3,1,3,1"></Setter>
</Style>

<Style TargetType="StackPanel" BasedOn="{StaticResource BasicStyle}"></Style>
<Style TargetType="DockPanel" BasedOn="{StaticResource BasicStyle}"></Style>

And I have a custom control with the following XAML:
XML
<UserControl x:Class="NeonMika.EightTracksPlayer.HeaderControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Margin="0">
    <DockPanel Margin="0" removed="{StaticResource HeaderColor}">
        <DockPanel DockPanel.Dock="Top">
            <TextBlock FontWeight="ExtraBlack" FontSize="24" DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Top">8tracksPlayer</TextBlock>
            <Image DockPanel.Dock="Left" Source="/NeonMika.EightTracksPlayer;component/Images/NeonMikaLogo.png" HorizontalAlignment="Left" Height="60" VerticalAlignment="Center"></Image>
        </DockPanel>
    </DockPanel>
</UserControl>


I have set Margin="0" on the UserControl _and_ on the DockPanel (to be sure they are).

But when I use this control like this
XML
<DockPanel VerticalAlignment="Stretch" Margin="0">
  <local:HeaderControl DockPanel.Dock="Top" Margin="0"></local:HeaderControl>
  <local:ControlArea DockPanel.Dock="Bottom" Margin="0">        </local:ControlArea>
  <ContentControl Name="ContentArea" Margin="0"></ContentControl>
</DockPanel>


there is still a Margin around my control. How is this possible? I sat every Margin to zero i could find :P

Thanks for your help!
Greets, Markus
Posted

1 solution

I found it out for myself (after a long way of trying and testing).
It's because the Window's template has a "built in" border.
Here is my way to solve it:
You change the Window's Template with your own ControlTemplate.
This ControlTemplate just contains a StackPanel with Margin=0 and other TemplateBindings (in my case, I only need the Background property:

<window.template>
  <controltemplate targettype="Window">
    <stackpanel margin="0" background="{TemplateBinding Background}">
      <contentpresenter></contentpresenter>
    </stackpanel>
  </controltemplate>
</window.template>


Probably this can help someone else too :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900