2017-08-17 63 views
0

我有一个从TextBoxWPF的造型自定义控件

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 
} 

我想用这样的样式该控件继承的类:

<Style x:Key="DecimalTextBoxGridStyle" TargetType="DecimalTextBox"> 
    <Setter Property="TextAlignment" Value="Right"/> 
    <Setter Property="FloatColor" Value="Black"/> 
    <Setter Property="BorderBrush" Value="Transparent"/> 
</Style> 

但它的风格跟我

enter image description here

DecimalT exbox类型不参与wpf项目

我该怎么做到这一点?

还有另外一种方法吗?

+1

什么'{X:类型NS:DecimalTextBox}'其中'ns'是包含'DecimalTextBox'的命名空间? – Maxim

+0

我要试一下 –

回答

5

附上XAML名称空间:

<Style x:Key="DecimalTextBoxGridStyle" TargetType="local:DecimalTextBox"> 

其中local被映射到其中DecimalTextBox类中定义的CLR名称空间:

<Window ... 
    xmlns:local="clr-namespace:WpfApplication1"