1
我在XAML有几个按钮的用户控件....XAML用户控件datatrigger
当我的C#代码更改为true“VideoEnable”属性我想改变一个按钮的颜色。
下面的代码编译,但崩溃,我无法找到一个合适的解决方案
<UserControl.Triggers>
<DataTrigger Binding="{Binding VideoEnable}" Value="true">
<Setter Property="Button.Background" Value="Green" TargetName="VideoButton" />
<Setter Property="Grid.Background" Value="Blue" TargetName="videoGrid" />
</DataTrigger>
</UserControl.Triggers>
现在我已经用下面的代码试过,它不会崩溃,但背景不会改变:■
<UserControl.Resources>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Videos}" Value="true">
<Setter Property="Button.Background" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
public string Videos
{
get { return m_videos; }
set
{
m_videos = value;
NotifyPropertyChanged("Videos");
}
}
好吧,我发现这个问题...
这是我的按钮
<Button DataContext="{Binding LensesBtn}" Margin="0,5,0,0" FontSize="14" FontWeight="Bold" Height="40" Opacity="0.8" HorizontalAlignment="Stretch" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
<Button.Background>#dbebf9</Button.Background>
<Button.BorderBrush>PowderBlue</Button.BorderBrush>
<Button.BorderThickness>4</Button.BorderThickness>
Lenses
</Button>
当我删除的DataContext,风格和背景属性所有的工作....
但我真的需要这个特性
任何提示?
你能发布错误信息吗? – 2010-03-13 11:46:11
应用程序只是崩溃。我认为我以错误的方式使用dataTrigger:s? – Bert 2010-03-13 18:34:40