Bug 21368 - Button text alignment breaks if the buttons are in a stack layout inside another layout and the button is clicked
Summary: Button text alignment breaks if the buttons are in a stack layout inside anot...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.1
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-16 10:31 UTC by Riccardo Moschetti
Modified: 2015-01-31 01:25 UTC (History)
8 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
button text moves... (131.09 KB, image/png)
2014-07-16 10:31 UTC, Riccardo Moschetti
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Riccardo Moschetti 2014-07-16 10:31:28 UTC
Created attachment 7389 [details]
button text moves...

See this example code.

http://forums.xamarin.com/discussion/20501/is-layout-badly-broken-or-am-i-just-not-getting-it


If you click on "Add Control", the "add control" text jumps to the left of the button...


using System;
using Xamarin.Forms;

namespace TestEditor
{
    public class App
    {
        static ScrollView _scrollView;
        static StackLayout _buttonsStack;
        static Grid _buttonsGrid;

        public static Page GetMainPage()
        {   
            _scrollView = new ScrollView
            {
                Orientation = ScrollOrientation.Horizontal,
                Content = new StackLayout { Orientation = StackOrientation.Horizontal },
                HeightRequest = 100
            };

            _buttonsGrid = new Grid {
                RowSpacing = 10,


            };

            _buttonsGrid.Children.Add (_scrollView,0,0);
            _buttonsGrid.Children.Add (new Button { Text = "Add Control",  Command = new Command (OnAddControl), WidthRequest=400 }, 0, 1);
            _buttonsGrid.Children.Add (new Button { Text = "Insert Control",  Command = new Command (OnInsertControl) }, 0, 2);
            _buttonsGrid.Children.Add (new Button { Text = "Remove Control",  Command = new Command (OnRemoveControl) }, 0, 3);
            _buttonsStack = new StackLayout{ Children = {_buttonsGrid} };


            return new ContentPage
            { 
                Content = new StackLayout
                {
                    Orientation = StackOrientation.Vertical,
                    Children =
                    {

                        _buttonsStack

                    }
                    }
            };
        }

        private static StackLayout ScrollStackLayout
        {
            get { return (StackLayout)_scrollView.Content; }
        }

        private static void OnAddControl()
        {
            ScrollStackLayout.Children.Add(new Button { Text = "hello" });
            ForceRelayout();
        }

        private static void OnInsertControl()
        {
            ScrollStackLayout.Children.Insert(0, new Button {  Text = "hello" });
            ForceRelayout();
        }

        private static void OnRemoveControl()
        {
            if (ScrollStackLayout.Children.Count > 0)
            {
                ScrollStackLayout.Children.RemoveAt(0);
                ForceRelayout();
            }
        }

        private static void ForceRelayout()
        {
            ScrollStackLayout.ForceLayout();
            _scrollView.ForceLayout();
        }
    }
}
Comment 1 Riccardo Moschetti 2014-07-16 10:33:27 UTC
the code above is the workaround code... the original code which shows the bug is here. sorry for that.

public class App
{ //broken alignment
    static ScrollView _scrollView;
    static StackLayout _buttonsStack;

    public static Page GetMainPage()
    {   
        _scrollView = new ScrollView
        {
            Orientation = ScrollOrientation.Horizontal,
            Content = new StackLayout { Orientation = StackOrientation.Horizontal },
            HeightRequest = 100
        };

        _buttonsStack = 
            new StackLayout
            {
                Children =
                {
                    new Button { Text = "Add Control", Command = new Command(OnAddControl) },
                    new Button { Text = "Insert Control", Command = new Command(OnInsertControl) },
                    new Button { Text = "Remove Control", Command = new Command(OnRemoveControl) }
                }
            };

        return new ContentPage
        { 
            Content = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children =
                {
                    _scrollView,
                    _buttonsStack
                }
            }
        };
    }

    private static StackLayout ScrollStackLayout
    {
        get { return (StackLayout)_scrollView.Content; }
    }

    private static void OnAddControl()
    {
        ScrollStackLayout.Children.Add(new Button { Text = "Hello" });
        ForceRelayout();
    }

    private static void OnInsertControl()
    {
        ScrollStackLayout.Children.Insert(0, new Button { Text = "Hello" });
        ForceRelayout();
    }

    private static void OnRemoveControl()
    {
        if (ScrollStackLayout.Children.Count > 0)
        {
            ScrollStackLayout.Children.RemoveAt(0);
            ForceRelayout();
        }
    }

    private static void ForceRelayout()
    {
        ScrollStackLayout.ForceLayout();
        _scrollView.ForceLayout();
    }
}
Comment 2 Arpit Jha 2014-08-21 04:35:15 UTC
I have checked this issue and able to reproduce it.

Steps to reproduce this issue.

1.Create a Xamarin PCL Forms application.
2.Add above code in App.cs .
3.Run the application.


I observed that when i clicked on Add Control text of control jumps to left and also observed that randomly click on Add control and Insert control .Added control text sometimes jumps to top ,sometimes right.


Screencast: http://screencast.com/t/1b6TI4vR6

Environment Info: 

XVS 3.3.47.0

Xamarin Form version:
1.2.2.6243
Comment 4 Rodja Trappe 2014-10-02 05:59:19 UTC
A smaller code example which reproduces this bug can be found at http://stackoverflow.com/questions/26056519/xamarin-forms-wrong-button-text-alignment-after-click-android. The Workaround is a very small addition to the ButtonRenderer:

public override void ChildDrawableStateChanged(Android.Views.View child) 
{ 
    base.ChildDrawableStateChanged(child); 
    Control.Text = Control.Text; 
}