I am using observable collection and dataTemplates to create generic panels, I have encountered an issue when my buttons colors (setted programaticly) do initializes, but once changed while running the color stays still.
Here is my Xaml code for the button:
<Button Grid.Column="0" Grid.Row="3" Background="{Binding Path=motionColor}" Command="{Binding Path=MotionPress}" Content="Motion" Height="51" Width="104" Style="{StaticResource MyButtonStyle}"/>
That's my DataTemplate:
<DataTemplate x:Key="GenericPanelTemplate" DataType="local:GenericPanel">
And here's the relevant backend code in GenericPanel.cs:
motionColor:
public Brush motionColor { get; set; }
The function eventually the button execute (tested and running):
public void MotionButton_Click()
{
motionColor = setColor((byte)Value.ON);
}
private Brush setColor(byte value)
{
switch (value)
{
case (byte)Value.OFF:
return Brushes.Red;
case (byte)Value.ON:
return Brushes.Green;
case (byte)Value.PROGRESS:
return Brushes.Yellow;
default:
return Brushes.Gray;
}
}
On start, the motionColor sets to be red, and the button does appear red, but when the value changed to Brushes.Green here it doesnt work anymore (debugging proves that the value changes correctly).
How do I make the button to check it's binded value and update the Background attribute?
If more code is needed please ask, I think these functions and Xaml lines are the only relevant ones.
Thanks for the help.
GenericPanelmust implement INotifyPropertyChanged interface ormotionColormust be a dependecy property. Otherwise your binding will never know that something has changed...