简体   繁体   English

Xamarin Forms 上的 ListView 仅在您重新保存 xml 页面时才显示数据……知道吗?

[英]ListView on Xamarin Forms only shows data when you resave the xml page… Any idea?

Well, I'm working on a Project on Xamarin forms where I drag data from SQL through an API, which is connected to my application.好吧,我正在做一个关于 Xamarin forms 的项目,我从 SQL 中拖动数据通过一个 ZDB974238714CA8DE4FZA 连接到我的应用程序。 The API works fine, it shows the information from SQL, and then on the ViewModel.cs and I can see the data con my ListView ItemSource={binding path} , but when the process is completed it doesn't show any data or info. API 工作正常,它显示来自 SQL 的信息,然后在ViewModel.cs上,我可以看到我的ListView ItemSource={binding path}的数据,但是当该过程完成时,它不显示任何数据或信息. It only displays once I hit Ctrl+s on my xaml page.它仅在我在 xaml 页面上按 Ctrl+s时显示。

ListView列表显示

<ListView ItemsSource="{Binding CompraCoba}" SeparatorVisibility="Default" SelectionMode="None" MinimumHeightRequest="100" HeightRequest="325" HasUnevenRows="False">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>

                <Grid RowSpacing="10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="3*" />
                    </Grid.ColumnDefinitions>

                    <Label Margin="10,10,10,0" HorizontalOptions="Start" x:Name="SucDlr" Text="{Binding monedaC}" FontSize="10" VerticalOptions="Start" TextColor="White"  Grid.Column="0" HorizontalTextAlignment="Start" />
                    <Label Margin="10,10,10,0" HorizontalOptions="Center" x:Name="MontoDlr" Text="{Binding valorC}" TextColor="White" FontSize="10" VerticalOptions="Start"  Grid.Column="1" />
                    <Label Margin="10,10,10,0" HorizontalOptions="End" x:Name="CambioDlr" Text="{Binding diaC}" TextColor="White" FontSize="10"  VerticalOptions="Start"  Grid.Column="2" />
                    <!--<Label Grid.ColumnSpan="4" BackgroundColor="#bababa" HeightRequest="1" HorizontalOptions="FillAndExpand" VerticalOptions="End" />-->

                </Grid>

            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Code-behind where vm = to my ViewModel. vm = 我的 ViewModel 的代码隐藏。 The GetCoba is an http request, it works fine GetCoba 是一个 http 请求,它工作正常

public ComprasTaxa()
{
    InitializeComponent();
    BindingContext = vm;
    vm.GetCoba(1);
}

Any suggestion would be an excellent help.任何建议将是一个很好的帮助。 Thanks in regards致谢

ViewModel视图模型

public async void GetCoba(int dias)
        {
            using (var client = new HttpClient())
            {
                var accessToken = Xamarin.Forms.Application.Current.Properties["token"];
                //Get Request
                var url = "https://masterxserver.azurewebsites.net/api/CompraTaxa/GetCoba?dia=" + dias + "";
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
                var result = await client.GetStringAsync(url);
                var CompraTaxaList = JsonConvert.DeserializeObject<List<CompraTaxaM>>(result);


                CompraCoba = new ObservableCollection<CompraTaxaM>(CompraTaxaList);
            }
        }
        ObservableCollection<CompraTaxaM> _compraCoba;

        public ObservableCollection<CompraTaxaM> CompraCoba
        {
            get
            {
                return _compraCoba;
            }
            set
            {
                _compraCoba = value;

                OnPropertyChanged();
            }
        }```

From your code and the description of the issue, it seems that the CompraCoba set is not notifying the View about the changed property.从您的代码和问题的描述来看,似乎CompraCoba集没有通知视图有关更改的属性。 You mentioned that the VM implemented INotifyPropertyChanged , could you please show that code?您提到虚拟机实现了INotifyPropertyChanged ,您能否显示该代码?

Also, it's possible that after you set value for the CompraCoba property, something can override, I would add a Debug.WriteLine and printing the value to be assigned and (important) thread it's assigned from ( Thread.CurrentThread.ManagedThreadId ) and make sure you get this print only once and only from the main thread (#1).此外,在您为CompraCoba属性设置值之后,有可能会覆盖某些东西,我会添加一个Debug.WriteLine并打印要分配的值和(重要的)线程,它是从( Thread.CurrentThread.ManagedThreadId )分配的,并确保您只能从主线程(#1)获得一次打印。 The fact that the data is loaded on Ctr+S means that property content is most likely correct but the thread it's been assigned from (or PropertyChanged event) is not.数据加载到 Ctr+S 上的事实意味着属性内容很可能是正确的,但分配给它的线程(或 PropertyChanged 事件)却不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有什么方法可以在Listview上双击事件并将列表数据发送到另一个页面 Xamarin Forms - Is there any way to have a double click event on Listview and send list data to another page in Xamarin Forms Xamarin Forms 单击列表视图上的菜单时如何打开弹出窗口 - Xamarin Forms how to open a popup when you clicked a menu on the listview Xamarin Forms-如何从输入的数据填充ListView? - Xamarin Forms - How to populate ListView from the data you entered? Xamarin.Forms Windows应用程序将XML数据加载到ListView中 - Xamarin.Forms Windows App load XML data into ListView 如何在xamarin表单中选择listview项目时打开另一个页面? - How to open another page when a listview item is selected in xamarin forms? 页面加载后,Xamarin Forms ListView程序化刷新不会在Android上停止 - Xamarin Forms ListView Programatic Refresh Not Stopping on Android When Page Loaded 使用命令加载页面(Xamarin.Forms)时填充ListView - Populate ListView when page is loaded (Xamarin.Forms) using a Command Xamarin.Forms - 数据更改时ListView不会更新 - Xamarin.Forms - ListView does not update when data changes Xml解析并绑定到Xamarin表单上的ListView - Xml parse and binding to listview on xamarin forms Xamarin.forms ListView单击到下一页 - Xamarin.forms ListView click to next page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM