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

Xamarin.Forms.ListView data interchanging position in latest XF version 3.5 #5200

Closed
FreakyAli opened this Issue Feb 11, 2019 · 1 comment

Comments

Projects
2 participants
@FreakyAli
Copy link

FreakyAli commented Feb 11, 2019

Description

The Xamarin Forms ListView's Data is overlapping, When I scroll (up or down) the list gets mixed up, the data is correct but in a different position and if I click on the item, it automatically changes the value to the right one and opens up the correct data... But then with the same code when I roll back to XF version 3.4 it works like a charm, Like there was nothing wrong, to begin with.
Note: I am using Group headers in my ListView.

Steps to Reproduce

  1. Use the below code in as your XAML :
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="OficinaDigitalX.Views.Interactions"
         xmlns:local="clr-namespace:OficinaDigitalX">
<ContentPage.BindingContext>
    <local:ViewModel.CarInteractions/>
</ContentPage.BindingContext>
<ContentPage.Content>
    <StackLayout>
        <ListView ItemsSource="{Binding Path=InteractionsList, Mode=TwoWay}">
            <ListView.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="110"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50" />
                    </Grid.RowDefinitions>
                    <Label Text="Fatura" FontSize="Medium" TextColor="Black" FontFamily="Bold" Grid.Column="0" Grid.Row="0" />
                    <Label Text="Intervenção" FontSize="Medium" TextColor="Black" Grid.Column="1" Grid.Row="0"/>
                    <Label Text="Total" FontSize="Medium" TextColor="Black" Grid.Column="2" Grid.Row="0"/>
                </Grid>
            </ListView.Header>
            <ListView.ItemTemplate>
                <DataTemplate>                       
                    <ViewCell>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="200"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="110"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="50"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Grid.Row="0" Text="{Binding Invoice}"
                            TextColor="#f35e20" FontSize="10"/>
                            <Label Grid.Column="1" Grid.Row="0" Text="{Binding Article}"
                            TextColor="#503026" FontSize="10" />
                            <Label Grid.Column="2" Grid.Row="0" Text="{Binding Total,StringFormat='{0} €'}"
                            TextColor="#503026" FontSize="10" />
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>
  1. the CS file should look like this:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Interactions : ContentPage
{
    public Interactions (CarInfo car)
    {
        InitializeComponent();
        BindingContext = new CarInteractions(car.VehicleId);
    }
    public Interactions()
    {

    }
}
  1. The View model that is CarInteractions:
public class CarInteractions : ViewModelBase
{

    private List<InteractionsInfo> _InteractionsList;

    public List<InteractionsInfo> InteractionsList
    {
        get
        {
            return _InteractionsList;
        }

        set
        {
            _InteractionsList = value;
            OnPropertyChanged("InteractionsList");
        }
    }

    public CarInteractions(int id)
    {
        GetFirstInteractionRow(id);
    }

    public CarInteractions() { }

   public void GetFirstInteractionRow(int id)
    {
        string command = "(**not important**)";
        string requestUriString = $"{MainPage.server}{command}/{id}";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString);
        HttpWebResponse response = null;

        try
        {
            response = (HttpWebResponse)request.GetResponse();
            using (var responseString = new StreamReader(response.GetResponseStream()))
            {
                InteractionsList = JsonConvert.DeserializeObject<ObservableCollection<InteractionsInfo>>(responseString.ReadToEnd());
            }
        }
        catch (WebException ex)
        {
            using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
            {

            }
            throw;
        }
    }
}

Expected Behavior:

The ListView data is added to the display correctly it does not change the position with anything else and click events/commands work properly on click.

Actual Behavior:

I add the data from the service and the data is added but the positions for the data are not correctly ordered, And when I scroll (up or down) the list gets mixed up, the data is right but in a different position and if I click on the item, it automatically changes the value to the right one...

Basic Information

  • Version with issue: Xamarin Forms v 3.5.0.129452
  • Last known good version: Xamarin Forms v 3.4.1029999
  • IDE: Visual Studio 2017
  • Platform Target Frameworks: Xamarin.Forms
    • iOS: 12.2.1.12
    • Android: 9.1.5.0
    • UWP: N/A
  • Android Support Library Version: 28.0.0.1
  • Nuget Packages:
  • Affected Devices: Android and iOS
@samhouts

This comment has been minimized.

Copy link
Member

samhouts commented Feb 12, 2019

Duplicate of #5184

@samhouts samhouts marked this as a duplicate of #5184 Feb 12, 2019

@samhouts samhouts closed this Feb 12, 2019

Triage automation moved this from New to Closed Feb 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment