-1

In my WPF application, a database is filled with personal data. Among them is if a person is alive, and if not, date and place of their death can be given. Where you can feed the data, I have a grid with two columns, in the left one is "place of death" text block, in the right is a TextBox. Same for date of death. If you select the "Alive" check box, I tried hiding both TextBlocks and TextBoxes with a style trigger and Visibility.Collapsed setter inside them, which seems really inconvenient.

Is there any other approach to do this?

Fabi
  • 199
  • 1
  • 14

2 Answers2

1

If you are using MVVM , you can bind the Visibility to a boolean and use a value converter to change it to collapsed.

Look for BooleanToVisibilityConverter.

0

You can play with the Height of Row to achieve your goal. XAML

<Grid Grid.Column="2" Grid.Row="1" x:Name="MyGrid">
   <Grid.RowDefinitions>
      <RowDefinition Height="60" />
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
      <RowDefinition Height="80" />
   </Grid.RowDefinitions>
</Grid>

Code Behind: C#

MyGrid.RowDefinitions(2).Height = new GridLength(0);

Code Behind: VB.NET

MyGrid.RowDefinitions(2).Height = New GridLength(0)
Habeeb
  • 7,601
  • 1
  • 30
  • 33