0
我是WPF技术的新手,我使用MVVM体系结构。当ViewModel中绑定的属性更改其值时,我想让边框改变颜色。让我们看一下代码:'使用数据触发器将颜色属性绑定到边框背景'
在我的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>
我将它绑定到我的境界:
<Border CornerRadius="1,1,0,0" Style="{StaticResource LineColor}" >
然后在我的ViewModel我带着简单的字符串:
public string lcolor="Blue";
但它没有工作。请帮助我。
编辑:我试了一下,如下所示:
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));
但它给我以下错误:
错误9
“PSWGS.Client.Module.CallControl。 ViewModels.CallControlViewModel'不包含'GetValue'的定义,也没有接受'PSWGS.Client.Module.CallControl.ViewMode'类型的第一个参数的扩展方法'GetValue' ls.CallControlViewModel”可以找到(是否缺少using指令或程序集引用?)
仍然给我错误: – deathrace
你没有提到任何在你的问题,它是什么错误呢? –
Error9“PSWGS.Client.Module.CallControl.ViewModels.CallControlViewModel”不包含“GetValue”的定义,也没有接受类型为“PSWGS.Client.Module.CallControl.ViewModels.CallControlViewModel”的第一个参数的扩展方法“GetValue” (缺少使用指令或程序集引用?)C:\ P1NG911 \ Product \ CAD \ Development \ Client \ Software \ Build \ CallControlModule \ ViewModels \ CallControlViewModel.cs 68 40 PSWGS.Client.Module.CallControl – deathrace