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:如何使用system';默认情况下是s按钮背景?_Wpf_Drop Down Menu_Default_Controltemplate_Aero - Fatal编程技术网

WPF:如何使用system';默认情况下是s按钮背景?

WPF:如何使用system';默认情况下是s按钮背景?,wpf,drop-down-menu,default,controltemplate,aero,Wpf,Drop Down Menu,Default,Controltemplate,Aero,我正在创建一个样式来更改按钮的ControlTemplate(它实际上在右侧添加了箭头,使按钮看起来像下拉按钮(wpf中缺少该按钮)) 在模板内部,我放置了实际的按钮(因为我需要的结果仍然像按钮一样-我只能更改ContentTemplate,但我需要将实际内容与箭头一起显示,将ContentPresenter放置在ContentTemplate中会产生堆栈溢出-wpf只是将模板扩展到presenter中并继续进行),和阿罗一起 我的问题是,我希望用户能够更改按钮的背景,因此我需要绑定backgr

我正在创建一个样式来更改按钮的ControlTemplate(它实际上在右侧添加了箭头,使按钮看起来像下拉按钮(wpf中缺少该按钮))

在模板内部,我放置了实际的按钮(因为我需要的结果仍然像按钮一样-我只能更改ContentTemplate,但我需要将实际内容与箭头一起显示,将ContentPresenter放置在ContentTemplate中会产生堆栈溢出-wpf只是将模板扩展到presenter中并继续进行),和阿罗一起

我的问题是,我希望用户能够更改按钮的背景,因此我需要绑定
background=“{TemplateBinding background}”
。这样,用户必须始终提供背景,否则它将为空。 为了防止出现这种情况,我知道我需要为背景提供默认值,所以我添加了

问题是,这个setter的值应该是什么?我假设wpf的内置样式会自动加载到每个应用程序中,我研究了aero.normalcolor.xaml,它们提供了
按钮normalbackground
样式,然后将其用作默认按钮样式
(aero.normalcolor.xaml,第47行)

但是,当我使用这个setter时,找不到静态资源,这正是我想要的。然后我将其更改为DynamicSource,但在这种情况下,按钮的背景保持透明-按钮的正常背景不被使用

我应该如何提供系统的按钮作为默认值?谢谢大家!

PS:dtto对于BorderBrush,BorderThickness-geez,似乎我不允许WPF作者一直使用的技巧:/

我的风格:

<Style TargetType="{x:Type ToggleButton}" x:Key="DropDownArrowStyle">
    <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
    <Setter Property="ToggleButton.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToggleButton}">
                <ToggleButton 
                    x:Name="PART_ToggleButton"
                    Margin="{TemplateBinding Margin}"
                    Padding="{TemplateBinding Padding}"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                    IsEnabled="{TemplateBinding IsEnabled}"
                    IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                    ContextMenu="{TemplateBinding ContextMenu}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Foreground="{TemplateBinding Foreground}"
                    FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
                    ClickMode="{TemplateBinding ClickMode}"
                    >
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <ContentPresenter
                            x:Name="ButtonContentPresenter"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Stretch"
                            Margin="{TemplateBinding Padding}"
                            Content="{TemplateBinding Content}"
                            Grid.Column="0"
                            />
                        <Border 
                            x:Name="PART_DownArrowBorder"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Background="Transparent"
                            Focusable="False"
                            Grid.Column="1"
                            >
                            <Path 
                                Focusable="False"
                                x:Name="PART_DownArrow"
                                Data="M 3,0 L 6.5,4 L 10,0" 
                                Width="12" 
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                Fill="Black" SnapsToDevicePixels="True"
                                >
                            </Path>
                        </Border>
                    </Grid>
                </ToggleButton>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

您需要定义要使用的颜色并参考系统颜色:

i、 e



有关可用系统颜色的更多信息

相关:
<SolidColorBrush 
   Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"
   x:Key="ButtonLinkBackground"/>
<Grid Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}"/>