Juan Pablo Gomez
Juan Pablo Gomez

Reputation: 5554

WPF styling custom control

I have a class that inherits from 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
}

I want to style this control using something like this:

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

But it style told me

enter image description here

DecimalTexbox type isn't admited in wpf project

How can I do to that ?

There is another approach ?

Upvotes: 0

Views: 60

Answers (1)

mm8
mm8

Reputation: 169420

Include the XAML namespace:

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

where local is mapped to the CLR namespace in which the DecimalTextBox class is defined:

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

Upvotes: 5

Related Questions