Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visibility.Collapse does not work in WPF

Visibility.Collapse doesnt work in my case. below is the XAML. If I try to hide the lblCountry and cmbCountry a white space is shown between zip and practice fields. There is no option to hide an entire row of a Grid.

<Grid>
    <Canvas Name="canDemographic" >

    </Canvas>
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <TextBlock Width="800" Height="50" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center"  FontFamily="Arial" FontSize="30" FontWeight="Bold" Visibility="Collapsed">
  Please review or enter your user information details:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *First Name:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" Middle Name:"></TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Last Name:
        </TextBlock>
        <TextBlock Name="tbEmail" Width="200" Height="30" Grid.Column="0" Grid.Row="12" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Email Address:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Address1:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="6" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" Address2:"></TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="7" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *City:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="8" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *State:
        </TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="9" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold">
  *Zip:
        </TextBlock>
        <TextBlock Name="lblCountry" Width="200" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="10" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" *Country:" Visibility="Collapsed"="></TextBlock>
        <TextBlock Width="200" Height="30" Grid.Column="0" Grid.Row="11" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold" Text=" Practice/Affiliation:"></TextBlock>

        <!-- Input fields -->
        <TextBox Name="txtFirstName" Width="200" Height="30" 
         Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold" MaxLength="20" TextChanged="txtFirstName_TextChanged" IsEnabled="True" />
        <TextBox Name="txtMiddleName" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold"
         Grid.Column="1" Grid.Row="3" MaxLength="10" IsEnabled="True" />
        <TextBox Name="txtLastName" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
         Grid.Column="1" Grid.Row="4" MaxLength="20" TextChanged="txtLastName_TextChanged" />
        <TextBox Name="txtEmail" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
         Grid.Column="1" Grid.Row="12" MaxLength="100"/>
        <TextBox Name="txtAddress1" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left"  FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="5" MaxLength="100" TextChanged="txtAddress1_TextChanged" />
        <TextBox Name="txtAddress2" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="6" MaxLength="100"/>
        <TextBox Name="txtCity" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="7" MaxLength="50" TextChanged="txtCity_TextChanged" />
        <TextBox Name="txtState" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="8" MaxLength="50" TextChanged="txtState_TextChanged" />
        <TextBox Name="txtZip" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="9" MaxLength="50" TextChanged="txtZip_TextChanged" />
        <ComboBox Name="cmbCountry" Width="200" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="0" Grid.Row="10" Grid.ColumnSpan="2" SelectionChanged="cmbCountry_SelectionChanged" ItemsSource="{Binding}" Visibility="Collapsed" />
        <TextBox Name="txtPractice" Width="200" Height="30" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="18" FontWeight="Bold"
        Grid.Column="1" Grid.Row="11" MaxLength="50"/>
    </Grid>
    <Button Name="btnExit" Height="30" VerticalAlignment="Bottom" Width="100" HorizontalAlignment="Left" Margin="21,0,0,12" BorderThickness="1" FontFamily="arial" Background="LightGray" FontSize="12pt" FontWeight="Bold" Click="btnExit_Click">Back</Button>
    <Button Name="btnNext" Height="30" VerticalAlignment="Bottom" Width="100" HorizontalAlignment="Right" Margin="0,0,21,12" BorderThickness="1" FontFamily="arial" Background="LightGray" FontSize="12pt" FontWeight="Bold" Click="btnNext_Click" IsEnabled="False" >Next</Button>
</Grid>
    </ScrollViewer>

like image 712
nitin Avatar asked Jan 21 '23 23:01

nitin


1 Answers

I think this is happening because you are explicitly setting the height of your rows(to 40), so even when rows contents are collapsed it takes space of 40. Try setting the Height of row to Auto.

like image 55
akjoshi Avatar answered Jan 30 '23 13:01

akjoshi