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
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
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).