Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF:内置样式在哪里定义_Wpf - Fatal编程技术网

WPF:内置样式在哪里定义

WPF:内置样式在哪里定义,wpf,Wpf,我在工具栏上有一个重复按钮。我希望它具有与工具栏按钮相同的视觉外观。但是ToolBar.ButtonStyleKey无法工作,因为TargetType不同。那么,在哪里定义了内置样式(针对各种主题)以及如何克隆RepeatButton的ToolBar.ButtonStyle?它们是在C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\PresentationFramework*程序集中定义的。您可以使用反编译器(如)提取模板,也可以在Visua

我在工具栏上有一个重复按钮。我希望它具有与工具栏按钮相同的视觉外观。但是ToolBar.ButtonStyleKey无法工作,因为TargetType不同。那么,在哪里定义了内置样式(针对各种主题)以及如何克隆RepeatButton的ToolBar.ButtonStyle?

它们是在
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\PresentationFramework*
程序集中定义的。您可以使用反编译器(如)提取模板,也可以在Visual Studio或Blend中的设计模式下右键单击控件,然后选择
编辑模板
->
编辑副本
将默认模板复制到XAML标记中

我尝试了这个,得到了
工具栏的
模板
,但没有工具栏按钮的样式。搜索在ToolBarButtonStyleKey处结束,但找不到WPF的ToolBarButtonStyle

就在那里:

<Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}">
    <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Control.Padding" Value="2"/>
    <Setter Property="Control.BorderThickness" Value="1"/>
    <Setter Property="Control.Background" Value="Transparent"/>
    <Setter Property="Control.BorderBrush" Value="Transparent"/>
    <Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
    <Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
    <Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
    <Setter Property="Control.VerticalContentAlignment" Value="Center"/>
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Name="Bd" Background="{TemplateBinding Control.Background}"
                  BorderBrush="{TemplateBinding Control.BorderBrush}"
                  BorderThickness="{TemplateBinding Control.BorderThickness}"
                  Padding="{TemplateBinding Control.Padding}" SnapsToDevicePixels="true">
                    <ContentPresenter HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                              SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="UIElement.IsMouseOver" Value="true">
                        <Setter TargetName="Bd" Value="{StaticResource ƻ}" Property="Border.BorderBrush"/>
                        <Setter TargetName="Bd" Value="{StaticResource ƺ}" Property="Border.Background"/>
                    </Trigger>
                    <Trigger Property="UIElement.IsKeyboardFocused" Value="true">
                        <Setter TargetName="Bd" Value="{StaticResource ƻ}" Property="Border.BorderBrush"/>
                        <Setter TargetName="Bd" Value="{StaticResource ƺ}" Property="Border.Background"/>
                    </Trigger>
                    <Trigger Property="ButtonBase.IsPressed" Value="true">
                        <Setter TargetName="Bd" Value="{StaticResource ƾ}" Property="Border.BorderBrush"/>
                        <Setter TargetName="Bd" Value="{StaticResource ƽ}" Property="Border.Background"/>
                    </Trigger>
                    <Trigger Property="UIElement.IsEnabled" Value="false">
                        <Setter Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" Property="Control.Foreground"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>


我无法帮助您回答问题的第一部分(默认样式是在哪里定义的?在某些主题中定义的,我想这些样式还是存储在某个DLL文件的某处…)。但要获取XAML表单中控件的(默认)控件模板,您可以按照此处给出的建议进行操作:。这是否回答了您的问题?谢谢mm8,我试过了,得到了工具栏的模板,但没有工具栏按钮的样式。搜索在ToolBarButtonStyleKey结束,但找不到WPF的ToolBarButtonStyle。谢谢!我想我必须对dotPeek有更多的了解。