0

In xamarin Android we have "Visibility.Gone;" to hide the button. In Xamarin Forms we have IsVisible="{Binding State}", but this only will make view invisible, space remain there.

Please let me know solution. Regards

Manik Mahendru
  • 185
  • 2
  • 12

1 Answers1

0

In your view model you need to have something similar to the following:

public bool State{
    get {
        return _state;
    }
    set {
        _state= value;
        RaisePropertyChanged ("State");
    }
}

According to the Xamarin documentation found here the element should be removed from the visual tree and not take up any space.

Edit:
I'm not sure how you're setting the Column="5" on your grid. There is no attribute for Grid that contains column; however, I am able to produce the effect you looking for with the following code.

 <Grid BackgroundColor="Gray">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        <Grid.Padding>
            <OnPlatform x:TypeArguments="Thickness" iOS="0,-3,-20,-3" Android="0, -5, 0, -5" WinPhone="20, 20, 20, 20" />
        </Grid.Padding>
        <BoxView Color="Blue" Grid.Column="0"></BoxView>
        <BoxView Color="Green" Grid.Column="1" IsVisible="{Binding State}"></BoxView>
        <BoxView Color="Blue" Grid.Column="2"></BoxView>
        <BoxView Color="Green" Grid.Column="3"></BoxView>
    </Grid>

Details:
You are correct in that setting the label visibility to false in a grid will maintain the space allocated to the control in the grid. What you can do is set the grid <ColumnDefinition Width="Auto" /> or <RowDefinition Height="Auto" /> and put your label into that column or row. This will automatically remove the space allocated for the control when the visibility is set to false. Below is a screenshot of the effect you are getting (left) and the effect after setting the Definition to Auto (right). enter image description here

Joshua Poling
  • 561
  • 8
  • 29
  • yes i have, but my question is i want to make my button "Gone" no "Invisible", there is big difference between "Gone" and "Invisible" Please check below link for difference http://stackoverflow.com/questions/11556607/android-difference-between-invisible-and-gone – Manik Mahendru Mar 15 '17 at 05:40
  • Yep you're correct. I misunderstood the problem. What type of layout contains the element you are trying to "Gone?" I've solved this issue a number of ways, but I'll need to know which layout you are using in order to supply you with a more direct solution. – Joshua Poling Mar 15 '17 at 12:36
  • I am using this, I want to Gone label. – Manik Mahendru Mar 16 '17 at 06:13