I have created a custom button that has a boolean flag on it to say whether it is selected or not. If it is selected i want to change the background color of the button to allow the user to know what control they are looking at quickly. The problem is that i can not get the trigger to work correctly. Everything that i have seen on here, i have tried but i still get errors during the InitializeComponent section of my code.
Here are the properties that i am dealing with
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
and here is my 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>
Currently the error i am getting is “Property can not be null on Trigger”
Thank you in advance for any assistance
You can use ToggleButton which has this property by default.