问题描述
我找到了如何使用以下方法更改箭头颜色:
这是 XAML 模板:
<Setter 属性="背景"><Setter.Value><ImageBrush ImageSource="Resources/Images/TextBoxEnabled.png" Stretch="None" AlignmentX="Left" AlignmentY="Bottom"/></Setter.Value></Setter><Setter Property="Foreground" Value="#FFFFFFFF"/><Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlNormalBorderKey, TypeInTargetAssembly={x:Type Themes1:ResourceKeys}}}"/><Setter Property="BorderThickness" Value="1"/><Setter Property="HorizontalContentAlignment" Value="Right"/><Setter Property="Focusable" Value="False"/><Setter Property="VerticalContentAlignment" Value="Center"/><Setter Property="TextAlignment" Value="Right"/><Setter Property="WatermarkTemplate"><Setter.Value><数据模板><ContentControl Content="{Binding}" Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" Focusable="False" Margin="0,0,3,0"/></数据模板></Setter.Value></Setter><Setter 属性="模板"><Setter.Value><ControlTemplate TargetType="{x:Type wpfTool:IntegerUpDown}"><wpfTool:ButtonSpinner x:Name="PART_Spinner" AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" ButtonSpinnerLocation="{Binding ButtonSpinnerLocation,RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" HorizontalContentAlignment="Stretch" IsTabStop="False" ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}" VerticalContentAlignment="Stretch"><wpfTool:WatermarkTextBox x:Name="PART_TextBox" AutoMoveFocus="{Binding AutoMoveFocus, RelativeSource={RelativeSource TemplatedParent}}" AutoSelectBehavior="{Binding AutoSelectBehavior, RelativeSource={RelativeSource TemplatedParent}}" AcceptsReturn="False" BorderThickness="0" Background="Transparent" ContextMenu="{TemplateBinding ContextMenu}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="{TemplateBinding IsTabStop}" IsUndoEnabled="True" MinWidth="20" Padding="{TemplateBinding Padding}" SelectAllOnGotus{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}" TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}" TextWrapping="NoWrap" TabIndex="{TemplateBinding TabIndex}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}" Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}"/></wpfTool:ButtonSpinner><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlMouseOverBorderKey, TypeInTargetAssembly={x:Type Themes1:ResourceKeys}}}"/></触发器><多数据触发器><MultiDataTrigger.Conditions><Condition Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="False"/><Condition Binding="{Binding AllowTextInput, RelativeSource={RelativeSource Self}}" Value="False"/></MultiDataTrigger.Conditions><Setter Property="IsReadOnly" TargetName="PART_TextBox" Value="True"/></MultiDataTrigger><DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True"><Setter Property="IsReadOnly" TargetName="PART_TextBox" Value="True"/></数据触发器><Trigger Property="IsKeyboardFocusWithin" Value="True"><Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlSelectedBorderKey, TypeInTargetAssembly={x:Type Themes1:ResourceKeys}}}"/></触发器><Trigger Property="IsEnabled" Value="False"><Setter 属性="背景"><Setter.Value><ImageBrush ImageSource="Resources/Images/TextBoxDisabled.png" Stretch="None" AlignmentX="Left" AlignmentY="Bottom"/></Setter.Value></Setter><Setter Property="Foreground" Value="#FFADD5FF"/><!-- <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>--></触发器><Trigger Property="IsFocused" Value="True"><Setter Property="FocusManager.FocusedElement" TargetName="PART_TextBox" Value="{Binding ElementName=PART_TextBox}"/></触发器></ControlTemplate.Triggers></控制模板></Setter.Value></Setter>
我尝试更改此部分,添加 SolidColorBrush x:Key,但我看不到任何更改.
<wpfTool:ButtonSpinner x:Name="PART_Spinner"...背景="{StaticResource IntegerUpDown.volume.Spinner.Static.Background}"
我尝试更改 BorderBrush:
我也尝试过这个解决方案,但代码混乱并显示错误关闭 XML 标记RepeatButton"不匹配:
wpf 工具包 datetimepicker 如何更改微调器的颜色一个>
代替 IntegerUpDown,我创建了一个类似的 ButtonSpinner 来查看模板代码.由于箭头颜色使用了 GlyphNormalForegroundKey,所以我查找了背景使用的内容,SpinnerButtonStyleKey 在 SpinnerButtonStyleKey>重复按钮.它适用于 IntegerUpDown.
我把这段代码放在一起,把它放在任何地方来覆盖按钮.
<Setter Property="Background" Value="Blue"/><Setter Property="BorderBrush" Value="Blue"/></风格>
https://wpftoolkit.codeplex.com/wikipage?title=IntegerUpDown&referringTitle=NumericUpDown
I'm trying to change the Arrow Button Background Color to Blue.
I believe it has something to do with SpinnerButtonStyleKey:
I was able to change the TextBox Background and Foreground using a png image in the Setter.
I found how to change the Arrow Color using:
<SolidColorBrush x:Key="{x:Static theme:ResourceKeys.GlyphNormalForegroundKey}" Color="White"/>
Here is the XAML template:
<Style x:Key="IntegerUpDownBlue" TargetType="{x:Type wpfTool:IntegerUpDown}">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="Resources/Images/TextBoxEnabled.png" Stretch="None" AlignmentX="Left" AlignmentY="Bottom"/>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="#FFFFFFFF"/>
<Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlNormalBorderKey, TypeInTargetAssembly={x:Type Themes1:ResourceKeys}}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Right"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Right"/>
<Setter Property="WatermarkTemplate">
<Setter.Value>
<DataTemplate>
<ContentControl Content="{Binding}" Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" Focusable="False" Margin="0,0,3,0"/>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type wpfTool:IntegerUpDown}">
<wpfTool:ButtonSpinner x:Name="PART_Spinner" AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" ButtonSpinnerLocation="{Binding ButtonSpinnerLocation, RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" HorizontalContentAlignment="Stretch" IsTabStop="False" ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}" VerticalContentAlignment="Stretch">
<wpfTool:WatermarkTextBox x:Name="PART_TextBox" AutoMoveFocus="{Binding AutoMoveFocus, RelativeSource={RelativeSource TemplatedParent}}" AutoSelectBehavior="{Binding AutoSelectBehavior, RelativeSource={RelativeSource TemplatedParent}}" AcceptsReturn="False" BorderThickness="0" Background="Transparent" ContextMenu="{TemplateBinding ContextMenu}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="{TemplateBinding IsTabStop}" IsUndoEnabled="True" MinWidth="20" Padding="{TemplateBinding Padding}" SelectAllOnGotFocus="{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}" TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}" TextWrapping="NoWrap" TabIndex="{TemplateBinding TabIndex}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}" Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}"/>
</wpfTool:ButtonSpinner>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlMouseOverBorderKey, TypeInTargetAssembly={x:Type Themes1:ResourceKeys}}}"/>
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="False"/>
<Condition Binding="{Binding AllowTextInput, RelativeSource={RelativeSource Self}}" Value="False"/>
</MultiDataTrigger.Conditions>
<Setter Property="IsReadOnly" TargetName="PART_TextBox" Value="True"/>
</MultiDataTrigger>
<DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="IsReadOnly" TargetName="PART_TextBox" Value="True"/>
</DataTrigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlSelectedBorderKey, TypeInTargetAssembly={x:Type Themes1:ResourceKeys}}}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="Resources/Images/TextBoxDisabled.png" Stretch="None" AlignmentX="Left" AlignmentY="Bottom"/>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="#FFADD5FF"/>
<!-- <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> -->
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="FocusManager.FocusedElement" TargetName="PART_TextBox" Value="{Binding ElementName=PART_TextBox}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
I tried changing this part, adding a SolidColorBrush x:Key, but I see no change.
<wpfTool:ButtonSpinner x:Name="PART_Spinner"...
Background="{StaticResource IntegerUpDown.volume.Spinner.Static.Background}"
I tried chaning BorderBrush:
<Setter Property="BorderBrush" Value="Blue"/>
I also tried this solution but the code is messed up and says "Error The closing XML tag "RepeatButton" is mismatched:
wpf toolkit datetimepicker how to change color of spinner
Instead of a IntegerUpDown, I created a similar ButtonSpinner to look through the template code. Since the Arrow Color used GlyphNormalForegroundKey I looked for what the Background was using, it was SpinnerButtonStyleKey in the RepeatButton. It worked on the IntegerUpDown.
I put together this code, place it anywhere to override the buttons.
<Style x:Key="{x:Static theme:ResourceKeys.SpinnerButtonStyleKey}" TargetType="RepeatButton">
<Setter Property="Background" Value="Blue" />
<Setter Property="BorderBrush" Value="Blue" />
</Style>
这篇关于如何更改按钮颜色 IntegerUpDown(扩展 WPF 工具包)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!