Click here to Skip to main content
15,939,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Here in the below xaml code i am trying to set the height of my row dynamically.
I want to fill the myLabel1 in two rows .I had set the mylabel2 visibility property to collapsed.. How shall i make the mylabel1 occupy the mylabel2 row also when mylabel's visibility is collapsed.

and mylabel2 should be able to occupy both rows if mylabel1 visibility is collapsed
Please see the below code
            <ColumnDefinition Width="150"></ColumnDefinition>
            <ColumnDefinition Width="150"></ColumnDefinition>
            <RowDefinition Height="50"></RowDefinition>
            <RowDefinition Height="50"></RowDefinition>
        <Label Background="Blue"  Content="mylabel" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2"></Label>
        <Grid Grid.Row="0" Grid.Column="1">
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="auto"></RowDefinition>
            <Label Background="Brown" Content="mylabel1" Grid.Column="0" Grid.Row="0"></Label>
            <Label Background="Brown" Content="mylabel2" Grid.Column="0" Grid.Row="1" Visibility="Collapsed"></Label>
Updated 2-Jun-14 22:45pm
kumar9avinash 3-Jun-14 3:45am    
hi you can also achive this using style trigger

1 solution

Hi,may be you can try like this

Arun you can decalre a property and assign the height value to this property and then throgh code behind bind it to the height of label 1

private string height;

        public string Height>
            get { return height; }
            set { height = value; }

if (label2.visibilty== coolapse)

Height= 150;

and in xaml
<Label Background="Brown" height={Binding Height} Content="mylabel1" Grid.Column="0" Grid.Row="0"></Label>
Share this answer
arun_pk 3-Jun-14 4:43am    
Thanks for the reply..
the solution you provided is correct . But i am looking for a code which doesnt write anything in code behind .. I could solve this please see the updated question.. But will not work if i want to make the mylabel1 visibilty collapsed and mylabel2 occupies the both rows

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900