【问题标题】:Styling Telerik WPF NumericUpDown Control样式化 Telerik WPF NumericUpDown 控件
【发布时间】:2024-01-17 04:25:01
【问题描述】:

我使用 Telerik WPF 控件并且需要将 NumericUpDown 控件添加到我的 UI。问题是当“按原样”使用时,它在视觉上不适合应用程序的其余部分

<TL;DR> This is a bigger application, that's not been written fully by me. Other people somehow managed to "import" other telerik controls and assign them other styles. Sadly, nobody's used the UpDown control before. </>

我将控件添加到我的 UI:

<telerik:RadNumericUpDown
  Minimum="0"
  Maximum="10"
  SmallChange="1"
  NumberDecimalDigits="0"
  IsInteger="True"
  Value="{Binding Path=Counter}" />

此外,我还为 ResourceDictionary 添加了一些样式:

  <Style TargetType="{x:Type telerikInput:RadNumericUpDown}">
    <Setter Property="Padding" Value="1"/>
    <Setter Property="Margin" Value="2"/>
    <Setter Property="Border.CornerRadius" Value="2" />
    <Setter Property="Border.Background" Value="{StaticResource ControlBackgroundBrush}" />
    <Setter Property="Border.BorderBrush" Value="{StaticResource SolidBorderBrush}" />
    <Setter Property="Border.BorderThickness" Value="1" />
  </Style>

这会处理一些基本的样式功能(边框、边距等)。一般来说,它看起来“足够好”。只有一个问题——当鼠标指针悬停在控件上时,它会变得有光泽。这不像我的其他控件的行为 - 有没有一种简单的方法可以消除这种效果?

我尝试过使用触发器:

<Style>
...
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
      <Setter Property="Foreground" Value="Red" />
      <Setter Property="Border.BorderBrush" Value="Black" />
      ...
  </Style.Triggers>
</Style>

但这并没有起到多大作用。我也尝试过设置IncreaseButtonContentTemplate 字段,但结果也不好。

【问题讨论】:

  • 试试&lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt;

标签: wpf xaml telerik numericupdown wpf-style


【解决方案1】:

您需要修改默认的ControlTemplates 并从中删除任何“闪亮和有光泽”的效果。最简单的方法是将默认模板从 Telerik 安装目录中的 Themes.Implicit 文件夹复制到您的解决方案中,然后根据您的要求进行编辑。

恐怕没有您可以简单地在控件上设置的“DisableEffects”属性。

【讨论】:

  • 好的,看来我不会从头开始重新实现样式。非常感谢。 Pfeeeew....那会很有趣... ;)