Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[regression/7.0.81] label created dynamically in code doesn't stretch like it should #14588

Closed
vsfeedback opened this issue Apr 14, 2023 · 11 comments
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter i/regression This issue described a confirmed regression on a currently supported version layout-grid s/needs-attention Issue has more information and needs another look s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[regression] [worked-in:17.5.3]
I am doing an app for android using .NET MAUI. Everything was fine until I updated VisualStudio to version 17.5.4.
My app populate the screen with a bunch of collectionview to display data, the number of collectionview depend on the number of item in a list, so I have to do it dynamically in code.
Here is my code to set the collectionview and its DataTemplate. When I was using VisualStudio 17.5.3, the Label in the DataTemplate was stretching to the size of the collectionview and with its property TextAlignment set to center, the text was appearing in the center of the collectionview.

                CollectionView leveeAskedCollectionView = new CollectionView();
                string bindPath = nameof(Joueurs) + $"[{i}].LeveeAsked";
                leveeAskedCollectionView.Background = Colors.Orange;
                leveeAskedCollectionView.SetBinding(ItemsView.ItemsSourceProperty, bindPath);
                leveeAskedCollectionView.ItemTemplate = new DataTemplate(() =>
                {
                    Label leveeAskedLabel = new Label();
                    leveeAskedLabel.Background = Brush.Red;
                    leveeAskedLabel.HorizontalTextAlignment = TextAlignment.Center;
                    leveeAskedLabel.SetBinding(Label.TextProperty, ".");
                    Grid.SetColumn(leveeAskedLabel, 0);
                    return leveeAskedLabel;
                });

Now since 17.5.4, this exact same code doesn't stretch the label anymore, it makes it the same size of the text and the text is always on the left side of the collectionview now. the property textalignment doesn't do anything now since the label's width is the same as the text it contain. I tried to set a collectionview with a label in its datatemplate in XAML and it works fine, the label stretch to the size of the collectionview. So it looks like it is only a problem when adding the control in code dynamically.
I attached a screen shot of the result. The orange part is the collectionview's background and the label containing only the text "0" has a red background. You can see that the label doesn't stretch like it did before.

Thank you.


Original Comments

Feedback Bot on 4/12/2023, 11:04 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@samhouts samhouts added t/bug Something isn't working area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter i/regression This issue described a confirmed regression on a currently supported version layout-grid labels Apr 14, 2023
@Sebastian1989101
Copy link

+1 this... [M]ulti-Platform [A]pp [U]ser [I]ssues continues to grow

@jsuarezruiz jsuarezruiz added the s/needs-repro Attach a solution or code which reproduces the issue label Apr 17, 2023
@samhouts
Copy link
Member

Suspect this is a duplicate of #14537

@samhouts samhouts changed the title label created dynamicaly in code doesn't strech like it should [regression/7.0.81] label created dynamicaly in code doesn't strech like it should Apr 17, 2023
@samhouts samhouts added this to the .NET 7 + Servicing milestone Apr 17, 2023
@hartez hartez changed the title [regression/7.0.81] label created dynamicaly in code doesn't strech like it should [regression/7.0.81] label created dynamically in code doesn't stretch like it should Apr 18, 2023
@hartez
Copy link
Contributor

hartez commented Apr 20, 2023

Suspect this is a duplicate of #14537

Seems likely, but it's impossible to say for sure without knowing the OP's Grid structure. #14537 is about controls spanning Grid columns, and the code shown here doesn't set any column spans. We need a repro, or at the very least we need to know what the Grid looks like.

@hartez hartez added the s/needs-info Issue needs more info from the author label Apr 20, 2023
@ghost
Copy link

ghost commented Apr 20, 2023

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Apr 24, 2023
@ghost
Copy link

ghost commented Apr 24, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@Phil11111
Copy link

Hello, I'm the one who posted that feedback. What do you need?

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/needs-repro Attach a solution or code which reproduces the issue s/no-recent-activity Issue has had no recent activity labels Apr 24, 2023
@Phil11111
Copy link

Here is some pictures of the issue and what it should be. I put some backgrounds colors so we can see. The orange part is the CollectionView and the red part is the Label in the datatemplate of the CollectionView.
Those 2 images is what happen with the same code above but in different version of visual studio.

Visual Studio V17.5.4. This is the bug. See how it doesn't strech to the size of the CollectionView and stick to the left side.
collectionview_label 17 5 4

Visual Studio V17.5.3. Works fine, strech like it should.
collectionview_label 17 5 3

@hartez
Copy link
Contributor

hartez commented May 3, 2023

@Phil11111 In order to know if it's the same bug as #14537, we would need to know what your Grid code/markup looks like. (I'm assuming there's a Grid involved because your DataTemplate includes Grid.SetColumn(leveeAskedLabel, 0);.)

@hartez hartez added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels May 3, 2023
@ghost
Copy link

ghost commented May 3, 2023

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@Phil11111
Copy link

Phil11111 commented May 3, 2023

@Phil11111 In order to know if it's the same bug as #14537, we would need to know what your Grid code/markup looks like. (I'm assuming there's a Grid involved because your DataTemplate includes Grid.SetColumn(leveeAskedLabel, 0);.)

Yes, you are right, the collection views are within a Grid.
By markup I assume you mean the XAML code...
Here is my complete XAML. The grid in question is the Grid at the complete end of the "main" Grid.
That Grid: <Grid x:Name="GameScoreDisplayGrid" Grid.Column="1"/>

Basically it is an empty Grid at first that I pass as a command parameter for a command, I then populate the Gris in code when the command is fired.

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="255"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>


        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
        
            <VerticalStackLayout Grid.Row="0">

                <Grid IsVisible="{Binding isGameStarted, Converter={StaticResource InvertedBoolConverter}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid Margin="0,5" Grid.Row="0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Label Text="{Binding CardsRequired}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
                        <Entry Text="{Binding Name}" Placeholder="Nom de joueur" Grid.Column="0" Grid.Row="1"/>
                        <Button Text="Ajout Joueur" Command="{Binding AddPlayerCommand}" Grid.Column="1" Grid.Row="1"/>
                    </Grid>

                    <CollectionView ItemsSource="{Binding Joueurs}" Grid.Row="1">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <SwipeView>
                                    <SwipeView.RightItems>
                                        <SwipeItems>
                                            <SwipeItem Text="Supprime" BackgroundColor="red"
                                                   Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodels:MainPageViewModel}}, Path=DeletePlayerCommand}"
                                                   CommandParameter="{Binding .}"/>
                                        </SwipeItems>
                                    </SwipeView.RightItems>
                                    <SwipeView.LeftItems>
                                        <SwipeItems>
                                            <SwipeItem Text="Modifie" BackgroundColor="Blue"
                                                   Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodels:MainPageViewModel}}, Path=ModifyPlayerCommand}"
                                                   CommandParameter="{Binding .}"/>
                                        </SwipeItems>
                                    </SwipeView.LeftItems>
                                    <Grid Margin="0,1">
                                        <Border>
                                            <Border.StrokeShape>
                                                <RoundRectangle CornerRadius="10" />
                                            </Border.StrokeShape>
                                            <Label Text="{Binding Name}" Margin="5, 10"/>
                                        </Border>
                                    </Grid>

                                </SwipeView>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>

                    <Button Text="Commencer la partie" Command="{Binding StartGameCommand}" CommandParameter="{Binding Source={x:Reference GameScoreDisplayGrid}}" Grid.Row="2" Margin="0,10,0,0"/>
                </Grid>
               

                <Button Text="Ronde Finie" Command="{Binding RoundFinishedCommand}">
                    <Button.IsVisible>
                        <MultiBinding Converter="{StaticResource BooleanAndConverter}">
                            <Binding Path="isGameStarted"/>
                            <Binding Path="isPlayersPlaying"/>
                            <Binding Path="isPlayersEnteringLevee" Converter="{StaticResource InvertedBoolConverter}"/>
                        </MultiBinding>
                    </Button.IsVisible>
                </Button>

                <Button Text="Passer à la ronde suivante" Command="{Binding NextRoundCommand}">
                    <Button.IsVisible>
                        <MultiBinding Converter="{StaticResource BooleanAndConverter}">
                            <Binding Path="isGameStarted"/>
                            <Binding Path="isPlayersPlaying" Converter="{StaticResource InvertedBoolConverter}"/>
                            <Binding Path="isPlayersChoosingLevee" Converter="{StaticResource InvertedBoolConverter}"/>
                            <Binding Path="isPlayersEnteringLevee" Converter="{StaticResource InvertedBoolConverter}"/>
                        </MultiBinding>
                    </Button.IsVisible>
                </Button>

                <Grid>
                    <Grid.IsVisible>
                        <MultiBinding Converter="{StaticResource BooleanOrConverter}">
                            <Binding Path="isPlayersChoosingLevee"/>
                            <Binding Path="isPlayersEnteringLevee"/>
                        </MultiBinding>
                    </Grid.IsVisible>


                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Label Text="{Binding UserInputMessage}" Grid.Row="0"/>

                    <CollectionView ItemsLayout="VerticalGrid, 4" ItemsSource="{Binding ButtonChoices}" IsVisible="{Binding isPlayersChoosingLevee}" Grid.Row="1">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <Button Text="{Binding .}" Margin="1" Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodels:MainPageViewModel}}, Path=InputAskedLeveeCommand}" CommandParameter="{Binding .}"/>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>

                    <CollectionView ItemsLayout="VerticalGrid, 4" ItemsSource="{Binding ButtonChoices}" IsVisible="{Binding isPlayersEnteringLevee}" Grid.Row="1">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <Button Text="{Binding .}" Margin="1" Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodels:MainPageViewModel}}, Path=InputDoneLeveeCommand}" CommandParameter="{Binding .}"/>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Grid>
                <!--<Label Text="{Binding isGameStarted, StringFormat='IsGameStarted: {0}'}"/>-->
                <!--<Label Text="{Binding isPlayersPlaying, StringFormat='isPlayersPlaying: {0}'}"/>-->
                <!--<Label Text="{Binding isPlayersChoosingLevee, StringFormat='isPlayersChoosingLevee: {0}'}"/>-->
                <!--<Label Text="{Binding isPlayersEnteringLevee, StringFormat='isPlayersEnteringLevee: {0}'}"/>-->
                <!--<Button Text="test button" Command="{Binding TestCommand}" CommandParameter="{Binding Source={x:Reference UserInputFlexLayout}}"/>-->
                <!--<Label Text="{Binding teststring}"/>-->
            </VerticalStackLayout>



            <StackLayout Grid.Row="2">
                <Button Text="Aide" Command="{Binding HelpCommand}"/>
                <!--This Button quit the App-->
                <Button Text="Quitter" Command="{Binding QuitAppCommand}" Margin="0,20,0,0"/>
            </StackLayout>
            
        </Grid>

        <!--This Grid contains the element for displaying the data, elements are added programmatically-->
        <Grid x:Name="GameScoreDisplayGrid" Grid.Column="1"/>

    </Grid>

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels May 3, 2023
@Redth Redth modified the milestones: .NET 7 + Servicing, .NET 8 GA Jul 12, 2023
@samhouts samhouts added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Aug 3, 2023
@ghost
Copy link

ghost commented Aug 3, 2023

Hi @Phil11111. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost closed this as completed Aug 13, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in MAUI SDK Ongoing Aug 13, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 12, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter i/regression This issue described a confirmed regression on a currently supported version layout-grid s/needs-attention Issue has more information and needs another look s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants