【问题标题】:How can I have my inherited TextBox use the style of the Button Type如何让我继承的 TextBox 使用按钮类型的样式
【发布时间】:2012-02-24 02:46:30
【问题描述】:

我正在使用继承自 TextBox 的自定义 TextBox:

Public Class MyTextBox: Inherits TextBox
    ...
End Class

我希望此类使用在 classic.xaml ResourceDictionary 中定义的样式。我试过这个:

 <Style x:Key="{x:Type uc:MyTextBox}" BasedOn="{StaticResource {x:Type TextBox}}"/>


    <Style x:Key="{x:Type TextBox}"
       BasedOn="{StaticResource {x:Type TextBoxBase}}"
       TargetType="{x:Type TextBox}">
    <!-- predefined style in classic.xaml-->
    </Style>

但我收到一条错误消息,指出样式只能基于 IFrameworkInputElement 类型。

这应该是微不足道的,不是吗?

【问题讨论】:

    标签: wpf styles basedon


    【解决方案1】:

    您需要将TargetType="{x:Type uc:MyTextBox}" 添加到您的样式中。

    【讨论】:

      猜你喜欢
      • 2016-05-13
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多