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