Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WPFDesign
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:45


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

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,356
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid