WPF设计问题(样式在app.xaml中设置,并且在本地设置时不会被覆盖) [英] WPF design question (Style set in app.xaml and is not overwritten when local set)

查看:95
本文介绍了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

推荐答案

我为自己找到了它(经过长时间的尝试和测试).
这是因为窗口的模板具有内置"边框.
这是我解决的方法:
您可以使用自己的ControlTemplate更改Window的模板.
此ControlTemplate仅包含Margin = 0和其他TemplateBindings的StackPanel(在我的情况下,我只需要Background属性:

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


这篇关于WPF设计问题(样式在app.xaml中设置,并且在本地设置时不会被覆盖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆