I am new to WPF technology and I am using MVVM architecture. I want my border to change color when property bound in ViewModel changes its value. lets look at the code :
In my XAML :
<Window.Resources>
<Style TargetType="{x:Type Border}" x:Key="LineColor">
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding lcolor}" Value="Blue">
<Setter Property="Background" Value="Green">
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
I am binding it to my border :
<Border CornerRadius="1,1,0,0" Style="{StaticResource LineColor}" >
Then In my ViewModel I took simple string :
public string lcolor="Blue";
But its not working at all. Please help me out.
EDIT: I tried it as follows:
public Boolean lcolor
{
get { return (Boolean)this.GetValue(StateProperty); }
set { this.SetValue(StateProperty, value); }
}
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
"lcolor", typeof(Boolean), typeof(CallControlViewModel));
But it’s giving me the following error :
Error 9
“PSWGS.Client.Module.CallControl.ViewModels.CallControlViewModel’ does not contain a definition for ‘GetValue’ and no extension method ‘GetValue’ accepting a first argument of type ‘PSWGS.Client.Module.CallControl.ViewModels.CallControlViewModel’ could be found (are you missing a using directive or an assembly reference?)
Read the data binding overview and about debugging bindings, once you understood everything you may come back.
lcoloris a field, it needs to be a property, further you might want to have a look atINPC.