WPF样式自定义控件

Jua*_*mez 0 c# wpf

我有一个继承自的类 TextBox

public class DecimalTextBox : TextBox
{

    #region Float Color 
    public static readonly DependencyProperty FloatColorProperty = DependencyProperty.Register("FloatColor", typeof(Color), typeof(DecimalTextBox), new FrameworkPropertyMetadata(Colors.Red));
    public Color FloatColor
    {
        get { return (Color)GetValue(FloatColorProperty); }
        set { SetValue(FloatColorProperty, value); }
    }
    #endregion

    . . . . ..  OTHER STUFF
}
Run Code Online (Sandbox Code Playgroud)

我想用这样的东西来设置这个控件的样式:

<Style x:Key="DecimalTextBoxGridStyle" TargetType="DecimalTextBox">
    <Setter Property="TextAlignment" Value="Right"/>
    <Setter Property="FloatColor" Value="Black"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

但它的风格告诉我

在此输入图像描述

在wpf项目中不会混淆DecimalTexbox类型

我怎么能这样做?

还有另一种方法吗?

mm8*_*mm8 5

包含XAML命名空间:

<Style x:Key="DecimalTextBoxGridStyle" TargetType="local:DecimalTextBox">
Run Code Online (Sandbox Code Playgroud)

where local映射到DecimalTextBox定义类的CLR命名空间:

<Window ...
    xmlns:local="clr-namespace:WpfApplication1"
Run Code Online (Sandbox Code Playgroud)