本文介绍了WPF设计问题(样式在app.xaml中设置,并且在本地设置时不会被覆盖)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的app.xaml中,除了其他样式外,我还具有以下内容:
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>
我有一个带有以下XAML的自定义控件:
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>
我在DockPanel的UserControl _and_上设置了Margin ="0"(确保它们是正确的).
但是当我像这样使用此控件时
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>
我仍然可以控制保证金.这怎么可能?我将每个保证金都坐零,我可以找到:P
感谢您的帮助!
问候,Markus
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
推荐答案
<window.template>
<controltemplate targettype="Window">
<stackpanel margin="0" background="{TemplateBinding Background}">
<contentpresenter></contentpresenter>
</stackpanel>
</controltemplate>
</window.template>
也许这也可以帮助其他人:)
Probably this can help someone else too :)
这篇关于WPF设计问题(样式在app.xaml中设置,并且在本地设置时不会被覆盖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!