我必须在我的 CustomControl 中创建一个 FontWeight 属性,但它在控制 FontWeights 时给了我错误。我该如何解决?
财产登记:
public static readonly DependencyProperty FontWeightProperty =
DependencyProperty.Register(
"FontWeight",
typeof(int),
typeof(WatermarkTextBox),
new PropertyMetadata(0));
属性(我们可以更改此属性,这是我的业余工作):
private int _watermarkFontWeight = 0;
public int WatermarkFontWeight
{
get
{
if (watermarkPassTextBox.FontWeight == FontWeights.Normal)
{
_watermarkFontWeight = 0;
}
else if (watermarkPassTextBox.FontWeight == FontWeights.SemiBold)
{
_watermarkFontWeight = 1;
}
else if (watermarkPassTextBox.FontWeight == FontWeights.Bold)
{
_watermarkFontWeight = 2;
}
else if (watermarkPassTextBox.FontWeight == FontWeights.ExtraBold)
{
_watermarkFontWeight = 3;
}
return _watermarkFontWeight;
}
set
{
if (value == 0)
{
SetProperty<int>(ref _watermarkFontWeight, value, "FontWeight");
watermarkPassTextBox.FontWeight = FontWeights.Normal;
}
else if (value == 1)
{
SetProperty<int>(ref _watermarkFontWeight, value, "FontWeight");
watermarkPassTextBox.FontWeight = FontWeights.SemiBold;
}
else if (value == 2)
{
SetProperty<int>(ref _watermarkFontWeight, value, "FontWeight");
watermarkPassTextBox.FontWeight = FontWeights.Bold;
}
else if (value == 3)
{
SetProperty<int>(ref _watermarkFontWeight, value, "FontWeight");
watermarkPassTextBox.FontWeight = FontWeights.ExtraBold;
}
}
}
错误:
Operator '==' cannot be applied to operands of type 'Windows.UI.Text.FontWeight' and 'Windows.UI.Text.FontWeight'
谢谢。