Set parental ownership of children in WPF

I created a status bar:

<StatusBar> <StatusBarItem > <WrapPanel> <Image Source="/MyApp;component/Images/icon.png" /> <TextBlock Name="_StatusbarUser" Text="Username" /> </WrapPanel> </StatusBarItem> </StatusBar> 

How to create a trigger, when I set the visibility of a text block to collapse, it will also be displayed as a status column of the trigger's parent.

I try to use the style below, but did not work

  <StatusBar Grid.Row="2" Name="_Statusbar"> <StatusBar.Resources> <Style TargetType="{x:Type StatusBarItem}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TextBlock}}, Path=Visibility}" Value="Collapsed"> <Setter Property="Visibility" Value="Collapsed"/> </DataTrigger> </Style.Triggers> </Style> </StatusBar.Resources> <StatusBarItem> <WrapPanel> <Image Source="/MyApp;component/Images/icon.png" /> <TextBlock Name="_StatusbarUser" Text="Username" /> </WrapPanel> </StatusBarItem> </StatusBar> 

Please help, thanks

+4
source share
1 answer

It is better to associate a parent property with a child property:

 <StatusBar> <StatusBarItem Visibility="{Binding ElementName=_StatusbarUser, Path=Visibility}"> <WrapPanel> <Image Source="/MyApp;component/Images/icon.png" /> <TextBlock Name="_StatusbarUser" Text="Username" /> </WrapPanel> </StatusBarItem> </StatusBar> 
+3
source

Source: https://habr.com/ru/post/1400191/


All Articles