Reputation: 1050
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.
Upvotes: 3
Views: 5239
Reputation: 18580
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" />
Upvotes: 3