tags:

views:

35

answers:

2

Hi,

I have a UserControl in XAML with a couple of buttons....

When the "VideoEnable" property in my C# code change to true i want to change the color of a button.

The following code compiles but crashes and I cant find a right solution

<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>
A: 

Now i have tried with the following code, it does not crash but the background does not change :s

<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");
        }
    }
Bert
A: 

Ok, I found the problem...

This is my button

        <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>

When I delete the DataContext, Style and Background properties it all works....

But i really need this properties

any tips?

Bert