views:

14

answers:

1

I have a DataTrigger setup like so:

<UserControl.Resources>
    <Style x:Key="resultTypeStyle">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Result, Path=Result.Type}" Value="Confirmation">
                <Setter Property="Control.Visibility" Value="Collapsed" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

And two controls that use it:

    <TextBlock Style="{StaticResource resultTypeStyle}" FontSize="14" Grid.Row="2">Condition</TextBlock>
    <myns:ConditionBuilderView Style="{StaticResource resultTypeStyle}" DataContext="{Binding Condition}" Grid.Row="3"/>

The result type is changed by a combo box.

When the result type is Confirmation then the TextBox disappears but the ConditionBuilderView stays visible unless I remove the DataContext attribute from it.

I need to set the DataContext attribute so that the control gets the right data.

What does setting the data context do that means the visibility property no longer works?

+2  A: 

You are actually changing the context used for the binding in the style of the ConditionBuilderView. So your DataTrigger looks for Result.Path on the bound Condition. If its just about Visibility this should work:

<TextBlock Style="{StaticResource resultTypeStyle}" FontSize="14" Grid.Row="2">Condition</TextBlock>
<ContentControl Grid.Row="3" Style="{StaticResource resultTypeStyle}" >
    <myns:ConditionBuilderView DataContext="{Binding Condition}"/>
</ContentControl>
MrDosu
Thanks MrDosu, that quite enlightening!
Matt Ellen