Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 滚动时ListView内容混淆_C#_Listview_Xamarin_Xamarin.forms_Grid - Fatal编程技术网

C# 滚动时ListView内容混淆

C# 滚动时ListView内容混淆,c#,listview,xamarin,xamarin.forms,grid,C#,Listview,Xamarin,Xamarin.forms,Grid,我试图列出我的sql数据库中的一些数据,但当我滚动(向上或向下)列表时,列表混淆了,数据是正确的,但位置不同,如果我单击该项,它会自动将值更改为正确的值 这是我的Interactions.xaml代码 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Ofici

我试图列出我的sql数据库中的一些数据,但当我滚动(向上或向下)列表时,列表混淆了,数据是正确的,但位置不同,如果我单击该项,它会自动将值更改为正确的值

这是我的Interactions.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>
}

CarInteractions(car.VehicleId)返回列表视图上显示的列表

这是我的CarInteractions.cs文件

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;
        }
    }


}
public类交互:ViewModelBase
{
私有列表_交互列表;
公共列表交互列表
{
得到
{
返回交互列表;
}
设置
{
_交互列表=值;
OnPropertyChanged(“交互列表”);
}
}
公共CarInteractions(int id)
{
GetFirstInteractionRow(id);
}
公共CarInteractions(){}
public void GetFirstInteractionRow(int id)
{
string命令=“(**不重要**)”;
字符串requestUriString=$“{MainPage.server}{command}/{id}”;
HttpWebRequest request=(HttpWebRequest)WebRequest.Create(requestUriString);
HttpWebResponse响应=null;
尝试
{
response=(HttpWebResponse)request.GetResponse();
使用(var responseString=newstreamreader(response.GetResponseStream()))
{
InteractionList=JsonConvert.DeserializeObject(responseString.ReadToEnd());
}
}
捕获(WebException ex)
{
使用(StreamReader=newstreamreader(ex.Response.GetResponseStream())
{
}
投掷;
}
}
}

最近发布的XF 3.5版存在一些问题,我建议您暂时将XF版本回滚到3.4版,直到这些错误得到解决

最近发布的XF 3.5版存在一些问题,我建议您暂时将XF版本回滚到3.4版,直到这些错误得到解决

我也是,但刚才我更新了新XF,它工作得很好。

我也是,但刚才我更新了新XF,它工作得很好。

您应该只在代码和XAML中设置BindingContext`尝试删除XAML部分,看看这是否对您有效<代码>如果此操作没有任何更改,请包括
CarInteractions.cs
文件。因此,我已删除该部件并添加了CarInteractions文件,但该文件也不起作用!:(等等,我让你在堆栈上添加here
CarInteractions.cs
,你在哪里添加的?代码中的某个地方?很抱歉我上传了它!我编辑了问题首先将
列表更改为
可观察集合
,不要担心它不会更改你的代码,因为它们都是
可枚举的
,你应该仅在代码和XAML中设置BindingContext`请尝试删除XAML部分,看看这是否对您有效!
如果没有任何更改,请包括
CarInteractions.cs
文件。因此,我已删除该部分并添加了CarInteractions文件,但它也不起作用!:(等等,我让你在堆栈上添加here
CarInteractions.cs
,你在哪里添加的?代码中的某个地方?很抱歉我上传了它!我编辑了问题首先将
列表
更改为
可观察集合
,不要担心它不会更改你的代码,因为它们都是
可枚举的
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;
        }
    }


}