我创建了一个自定义按钮,上面有一个布尔标志来说明它是否被选中。如果它被选中,我想更改按钮的背景颜色,以让用户快速知道他们正在查看的控件。问题是我无法让触发器正常工作。我在这里看到的所有内容,我都尝试过,但在代码的 InitializeComponent 部分仍然出现错误。
这是我正在处理的属性
Private mIsSelected As Boolean = False
Public Property IsSelected() As Boolean
Get
Return mIsSelected
End Get
Set(ByVal value As Boolean)
mIsSelected = value
End Set
End Property
Public Shared ReadOnly MyBackgroundProperty As DependencyProperty = DependencyProperty.Register("MyBackground",
GetType(LinearGradientBrush), GetType(RentAdjButtons),
New PropertyMetadata(New LinearGradientBrush(ColorConverter.ConvertFromString("#3366CC"), ColorConverter.ConvertFromString("#0000FF"), New System.Windows.Point(0.5, 0), New System.Windows.Point(0.5, 1))))
Private mMyBackground As New LinearGradientBrush
Public Property MyBackground() As LinearGradientBrush
Get
Return mMyBackground
End Get
Set(ByVal value As LinearGradientBrush)
mMyBackground = value
End Set
End Property
这是我的 XMAL
<Style TargetType="Com:RentAdjButtons">
<Setter Property="MyBackground" Value="{StaticResource DefaultBackground}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="MyBackground" Value="{StaticResource SelectedButton}" />
</Trigger>
</Style.Triggers>
</Style>
目前我得到的错误是“触发时属性不能为空”
预先感谢您的任何帮助