Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Updating RowDefinitions via C# or Hot Reload doesn't work #13154

Closed
BretJohnson opened this issue Dec 15, 2020 · 1 comment · Fixed by #13320
Closed

[Bug] Updating RowDefinitions via C# or Hot Reload doesn't work #13154

BretJohnson opened this issue Dec 15, 2020 · 1 comment · Fixed by #13320
Assignees
Labels
a/layout blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. e/5 🕔 5 hotreload Forms bugs that affect Hot Reload t/bug 🐛

Comments

@BretJohnson
Copy link

Description

When RowDefinitions is set to a populated RowDefinitionCollection, that change doesn't cause the Grid to be updated.
Updating an existing RowDefinitions value triggers an update, but setting a completely new value doesn't.

Steps to Reproduce

  1. Create XAML like this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FormsScratchPad.MainPage">

    <StackLayout>
        <Button Clicked="Button_Clicked" Text="Update RowDefinitions"/>
        <Grid x:Name="MyGrid" RowDefinitions="20,20,20">
            <Label Grid.Row="1" Text='Hey'/>
            <Label Grid.Row="2" Text='Hey'/>
            <Label Grid.Row="3" Text='Hey'/>
        </Grid>
    </StackLayout>

</ContentPage>

with code behind like this:

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            var row1 = new RowDefinition();
            row1.Height = 400;

            var row2 = new RowDefinition();
            row2.Height = 100;

            var row3 = new RowDefinition();
            row3.Height = 200;

            var rows = new RowDefinitionCollection();
            rows.Add(row1);
            rows.Add(row2);
            rows.Add(row3);

            MyGrid.RowDefinitions = rows;
        }
    }
  1. Run the app and hit the Update RowDefinitions button

Expected Behavior

The Grid should update, with the new row heights.

Actual Behavior

Nothing changes visually, at least not at first.
Note that if the code is changed to set an empty collection first and then update the collection, like below, it works. But it doesn't work when the property is set directly with the fully populated collection.


            var rows = new RowDefinitionCollection();
            MyGrid.RowDefinitions = rows;
            rows.Add(row1);
            rows.Add(row2);
            rows.Add(row3);

This is a problem for Hot Reload, when updating RowDefinitions using the string syntax (RowDefinitions="400,100,200"). In that case Hot Reload invokes the type converter, getting a fully populated RowDefinitionCollection, then sets the RowDefinitions property & the grid doesn't update.

Basic Information

  • Version with issue: 5.0 pre5
  • Last known good version: none known
  • Platform Target Frameworks:
    • Android: VS 16.9
  • Android Support Library / AndroidX Version:
@BretJohnson BretJohnson added t/bug 🐛 s/unverified New report that has yet to be verified labels Dec 15, 2020
@samhouts samhouts added this to New in Triage Dec 15, 2020
@BretJohnson BretJohnson added the hotreload Forms bugs that affect Hot Reload label Dec 15, 2020
@hartez hartez removed the s/unverified New report that has yet to be verified label Jan 6, 2021
@hartez hartez added this to To do in Other Ready For Work via automation Jan 6, 2021
@hartez hartez removed this from New in Triage Jan 6, 2021
@BretJohnson BretJohnson added the blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. label Jan 6, 2021
@BretJohnson
Copy link
Author

Corresponding AzDO Hot Reload bug: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1257828

StephaneDelcroix added a commit that referenced this issue Jan 7, 2021
We invalidate when the items of the row/col def are modified. With this,
we also invalidate when the full collection is swapped.

- fixes #13154
@Redth Redth added this to To do in vNext+1 (5.0.0) Jan 13, 2021
@Redth Redth moved this from To do to Blockers in vNext+1 (5.0.0) Jan 13, 2021
@Redth Redth moved this from Blockers to To do in vNext+1 (5.0.0) Jan 13, 2021
@rmarinho rmarinho moved this from To do to In Progress in vNext+1 (5.0.0) Jan 15, 2021
Other Ready For Work automation moved this from To do to Done Jan 15, 2021
vNext+1 (5.0.0) automation moved this from In Progress to Done Jan 15, 2021
rmarinho pushed a commit that referenced this issue Jan 15, 2021
We invalidate when the items of the row/col def are modified. With this,
we also invalidate when the full collection is swapped.

- fixes #13154
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/layout blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. e/5 🕔 5 hotreload Forms bugs that affect Hot Reload t/bug 🐛
Projects
Development

Successfully merging a pull request may close this issue.

3 participants