Click here to Skip to main content
12,956,512 members (77,450 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
In my app.xaml, I have (beside other styles) the following:
<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:
<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
<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 27-Sep-12 5:45am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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 :)
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100