所有控件的Wpf公共边框样式

所有控件的Wpf公共边框样式,wpf,app.xaml,Wpf,App.xaml,我在wpf工作 我使用以下控件: 按钮 文本框 文本块 标签 TreeView 列表视图 组合框 有没有办法为所有这些设置默认边框(在App.xaml中)? 谢谢 Ilan除了为每种类型进行设置外,我不知道其他方法,例如: <Style TargetType="{x:Type Button}"> <Setter Property="BorderThickness" Value="3"/> <Setter Property="BorderBrush"

我在wpf工作
我使用以下控件: 按钮
文本框
文本块
标签
TreeView
列表视图
组合框
有没有办法为所有这些设置默认边框(在App.xaml中)?
谢谢
Ilan

除了为每种类型进行设置外,我不知道其他方法,例如:

<Style TargetType="{x:Type Button}">
    <Setter Property="BorderThickness" Value="3"/>
    <Setter Property="BorderBrush" Value="Green"/>
</Style>

或者如果您已经有了一些默认样式,例如按钮

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="BorderThickness" Value="3"/>
    <Setter Property="BorderBrush" Value="Green"/>
</Style>

这将为应用程序中的所有按钮设置默认的
BorderThickness
BorderBrush
。您还可以在此处定义
OnMouseOver
等行为


对于TextBlock,如果您想要有一些边框,您也必须定义模板,因为
TextBlock
是基本控件,没有
border
。如果您想要边框,您可以使用
标签
,它只是
文本块
,边框在外。

我不知道除了为每种类型设置外的其他方法,比如:

<Style TargetType="{x:Type Button}">
    <Setter Property="BorderThickness" Value="3"/>
    <Setter Property="BorderBrush" Value="Green"/>
</Style>

或者如果您已经有了一些默认样式,例如按钮

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
    <Setter Property="BorderThickness" Value="3"/>
    <Setter Property="BorderBrush" Value="Green"/>
</Style>

这将为应用程序中的所有按钮设置默认的
BorderThickness
BorderBrush
。您还可以在此处定义
OnMouseOver
等行为


对于TextBlock,如果您想要有一些边框,您也必须定义模板,因为
TextBlock
是基本控件,没有
border
。如果您想要边框,您可以使用
标签
,它只是
文本块
,边框在外。

对于所有使用标准边框的内容,您可以创建以下内容:

<Style TargetType="{x:Type Border}">
    <Setter Property="BorderThickness" Value="10"/>
</Style>


如果在以其他方式创建的任何控件边框中,您将需要手动覆盖它。

对于使用标准边框的所有内容,您可以创建以下内容:

<Style TargetType="{x:Type Border}">
    <Setter Property="BorderThickness" Value="10"/>
</Style>

如果在任何以其他方式创建的控件边框中,您需要手动覆盖它。

多亏了all
定义边框样式的解决方案有效
唯一的例外是文本框,因为文本框中没有边框
我为TextBox找到的解决方案是如下定义TextBox样式

<Style TargetType="{x:Type TextBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <!-- Modify default template, to change triggers -->
                    <ControlTemplate TargetType="{x:Type TextBoxBase}">
                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                            <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

宜兰

感谢大家
定义边框样式的解决方案有效
唯一的例外是文本框,因为文本框中没有边框
我为TextBox找到的解决方案是如下定义TextBox样式

<Style TargetType="{x:Type TextBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <!-- Modify default template, to change triggers -->
                    <ControlTemplate TargetType="{x:Type TextBoxBase}">
                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                            <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

宜兰