Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How can I prevent RelativeLayout from re-drawing when child changes?

$
0
0

I've got a relative layout that contains a grid I position slightly off screen. The user needs to press a button in order for the grid to "open" (using LayoutTo). Once open, there is a toggle switch that allows them to change settings.

My Problem:
When the switch is toggled, the layout is completely re-drawn, moving the grid back to the original starting point. I've been looking at the overloads in the Page class, and I can't seem to come up with anything.

Is there a way to prevent the re-drawing of the view after the toggle switch is toggled? This happens on both iOS and Android.

Layout

    <RelativeLayout  x:Name="Container"
       VerticalOptions="FillAndExpand"
                    HorizontalOptions="FillAndExpand">

    <!-- other layout bits-->

        <!-- this legend is actually a GRID -->
        <ctrl:OutageMapLegend x:Name="ReferenceOutageMapLegend" Opacity="0" InputTransparent="True" />
        <ctrl:OutageMapLegend x:Name="OutageMapLegend"
                              RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ReferenceOutageMapLegend, Property=Width, Factor=-1, Constant=40}"/>

    <!-- other layout bits-->
    </RelativeLayout>

Switch - inside the OutageMapLegend Grid

            <Switch HorizontalOptions="CenterAndExpand"
                    Scale=".7"
                    IsToggled="{Binding ShowPlannedOutages}"
                    IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBoolConverter}}" />

Code to position the Grid

        private async Task ToggleHamburgerMenu()
        {
            var legendBounds = Bounds;
            legendBounds.X = _menuIsOpen ? -(legendBounds.Width - 40) : 0;
            _easing = _menuIsOpen ? Easing.SpringOut : Easing.SpringIn;
            _menuIsOpen = !_menuIsOpen;

            await this.LayoutTo(legendBounds, _transitionSpeed, _easing);
        }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>