3

I have implemented a WPF user control and what i want to achieve here is on mouseover on Main Grid some stack panels should hide. And i need to have multiple triggers conditions. Despite looking everywhere i am unable to find what am i doing wrong. UserControl Resources are as follow

<UserControl.Resources>
    <Style x:Key="StackViewStyle" TargetType="{x:Type StackPanel}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Grid},Path=IsMouseOver}" Value="True" />
                    <Condition Binding="{Binding Path=FileState, RelativeSource={RelativeSource Self}}" Value="Uploading" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Visibility" Value="Collapsed"/>
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

Data binding is working fine, because when i put in a test label to check its value it was "uploading". If i remove FileState Condition it starts working. I am using it as

<StackPanel Name="StackViewCount" Style="{StaticResource StackViewStyle}">
    ...
</StackPanel>

While looking output window i found this error

BindingExpression path error: 'FileState' property not found on 'object' ''StackPanel' (Name='StackViewCount')'. BindingExpression:Path=FileState; DataItem='StackPanel' (Name='StackViewCount'); target element is 'StackPanel' (Name='StackViewCount'); target property is 'NoTarget' (type 'Object')

So how can i tell the binding to look for FileState in UserControl not stackpanel

Now when i changed condition to

<Condition Binding="{Binding Path=FileState}" Value="Uploading" />

I dont see any errors but still it does not work.

Natxo
  • 2,917
  • 1
  • 24
  • 36
Mirza Bilal
  • 891
  • 11
  • 34
  • FileState is a property of StackPanel? – D J Sep 24 '13 at 00:22
  • No it is a property of UserControl. @DJ i think i am missing the point here, how could i use binding of usercontrol. As i have already tried "{Binding Path=FileState}". – Mirza Bilal Sep 24 '13 at 00:30
  • Does `FileState` say `uploading` or `Uploading`? Note that case matters. Also, check the output window for errors. – Arian Motamedi Sep 24 '13 at 01:45
  • Obvious i know case sensitivity matters here. Second thing you raised, give me a clue as it is searching for FileState in stack panel, which is not a stack panel proper but of parent usercontrol's. – Mirza Bilal Sep 24 '13 at 01:55

1 Answers1

3

Since FileState is property of your UserControl and it is ancestor of StackPanel you have to bind to ancestor like:

<Condition Binding="{Binding Path=FileState, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Uploading" />
Nitin
  • 18,344
  • 2
  • 36
  • 53