Thursday, 15 July 2010

wpf - how do I collapse parent content if all children are collapsed -


I want to show / collapse a panel (steppanel, grid etc.) if every child collapses and if It appears at least one if its children are visible again.

Would this be the best way to get it? (Converter, trigger, second thing?) Thanks!

I have done a converter but when I change the visibility of children, then it is not a fire. Public class HasChildrenVisibilityConverter: IValueConverter {Public Object Convert (Object Value, Type Type, Object Parameter, CultureInfo Culture) {Value as a Panel Parent = Panel; Forchha (different child in parent. Child.oftepe & lt; UIElement & gt; ()) {if (child.IsVisible) visibility in return View; } Changed Visibility Collapsed; } Public Object Convertback (Object Value, Object Parameter, CultureInfo Culture) {Return Value; // no ilplodo}}

This is an XML example

   & Lt; /Window.Resources> & Lt; StackPanel Visibility = "{Binding Relative Soros = {Relative Asus}, Converter = {Static Resources Converter}}" & gt; & Lt; Textblocks x: name = "lesson 1" & gt; Lesson 1 & lt; / TextBlock & gt; & Lt; Textbox x: name = "text2" & gt; Lesson 2 & lt; / TextBlock & gt; & Lt; / StackPanel & gt;  

A MultidataTrgr will work quite well here. Here is a simple example with a stackpanel and some TextBlock I declare a trigger in style and that style is relevant to StackPanel

MainWindow.xaml

& Lt; Condition binding = "{binding element name = txtDescription, path = visibility}" value = "abbreviated" /> & Lt; /MultiDataTrigger.Conditions> & Lt; Setter property = "visibility" value = "collapsed" /> & Lt; / MultiDataTrigger & gt; & Lt; MultiDataTrigger & gt; & Lt; MultiDataTrigger.Conditions & gt; & Lt; Condition binding = "{binding element name = txtName, path = visibility}" value = "visible" /> & Lt; Condition binding = "{binding element name = txtDescription, path = visibility}" value = "visible" /> & Lt; /MultiDataTrigger.Conditions> & Lt; Setter property = "visibility" value = "view" /> & Lt; / MultiDataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /Window.Resources> & Lt; StackPanel & gt; & Lt; StackPanel Style = "{StaticResource ShowHideStyle}" height = "300" width = "300" background = "red" & gt; & Lt; TextBlock x: name = "txtName" text = "name" /> & Lt; TextBlock x: name = "txtDescription" text = "description" /> & Lt; / StackPanel & gt; & Lt; Button x: name = "btn hedge" width = "100" height = "30" content = "hide" click = "btnhead_click" /> & Lt; Button x: name = "show btn" width = "100" height = "30" content = "show" click = "btn shaw_click" /> & Lt; / StackPanel & gt;

Menindex.xml CS adds just button click events to hide / show child elements

  Private zeros btnHide_Click (Object Sender, RoutedEventArgs e) {TxtDescription.Visibility = System.Windows.Visibility.Collapsed; TxtName.Visibility = System.Windows.Visibility.Collapsed; } Private Zero btnShow_Click (Object Sender, RoutedEventArgs e) {txtDescription.Visibility = System.Windows.Visibility.Visible; TxtName. Visibility = System. world. Visibility View; }  

No comments:

Post a Comment