[英]WPF styling custom control
我有一個從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
}
我想使用如下樣式設置此控件的樣式:
<Style x:Key="DecimalTextBoxGridStyle" TargetType="DecimalTextBox">
<Setter Property="TextAlignment" Value="Right"/>
<Setter Property="FloatColor" Value="Black"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Style>
但是它告訴我
WPF項目中不允許DecimalTexbox類型
我該怎么辦?
還有另一種方法嗎?
包括XAML命名空間:
<Style x:Key="DecimalTextBoxGridStyle" TargetType="local:DecimalTextBox">
其中local
映射到在其中定義DecimalTextBox
類的CLR名稱空間:
<Window ...
xmlns:local="clr-namespace:WpfApplication1"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.