简体   繁体   中英

MultiDataTrigger not working with binding path condition

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.

由于FileStateUserControl属性,并且它是StackPanel祖先,因此您必须bind to ancestor如:

<Condition Binding="{Binding Path=FileState, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Uploading" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM