views:

1378

answers:

2

I wanted to change the Foreground color when I selected a listboxItem and I did it using this bit of code:

<DataTrigger Binding="{Binding  
RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
                            <Setter TargetName="descriptionTB" Property="Foreground" Value="#000"/>
</DataTrigger>

You can find the answer here.

But if I want a designer to do this in Blend, how would he do it without drilling into xaml?

Thank you

+1  A: 

Maybe I'm misunderstanding the question but can't you just create a style resource for descriptionTB and let the designer only deal with that style definition and not the binding?

<DataTrigger Binding="..">
    <Setter TargetName="descriptionTB" Property="Style" Value="{StaticResource DescriptionTextBoxStyle}" />
</DataTrigger>

In the resources section of your control or window you add the style definition:

<Style TargetType="{x:Type TextBox}" x:Key="DescriptionTextBoxStyle">
    <Setter Property="Foreground" Value="#000" />
</Style>

If you want to further isolate the designer from the mechanics of the UI you can create a resource dictionary in a separate xaml file in which you can collect all styles meant for the designer. Then you can merge that resource dictionary with your control's or application's main resources.

Yanko Yankov
+1  A: 

Artur,

The Triggers designer in Expression Blend only allows adding and modifying EventTriggers and Property triggers. I haven't found a way to add DataTriggers with Blend. I'm also not sure how to set RelativeSource Binding using Blend either. I've always handed code the XAML for test and use Blend for everything else.

Alan Le