[英]WPF styling custom control
I have a class that inherits from TextBox
我有一个从
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 但是它告诉我
DecimalTexbox type isn't admited in wpf project WPF项目中不允许DecimalTexbox类型
How can I do to that ? 我该怎么办?
There is another approach ? 还有另一种方法吗?
Include the XAML namespace: 包括XAML命名空间:
<Style x:Key="DecimalTextBoxGridStyle" TargetType="local:DecimalTextBox">
where local
is mapped to the CLR namespace in which the DecimalTextBox
class is defined: 其中
local
映射到在其中定义DecimalTextBox
类的CLR名称空间:
<Window ...
xmlns:local="clr-namespace:WpfApplication1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.