ListView控件数据绑定的Windows 8.1应用程序商店 [英] ListView Data Binding for Windows 8.1 Store Apps

查看:198
本文介绍了ListView控件数据绑定的Windows 8.1应用程序商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图将桌面程序我到一个应用程序取得了的Windows 8.1 使用的Visual Studio 2013 的Datagrid 是pcated对于此版本,所以我试图转移到的ListView 翻译那些去$ P $。 I $ pviously使用列表视图在其他桌面应用程序p $,但它看起来像发生了很多变化。我遇到的问题是填充我的的ListView 从我的数据库。我通过连接WCF服务并通过code步进,我可以看到我得到正确的数据,我只是不能让它出现在我的ListView。我的preferred最终的结果将是一个列表视图随着信息3列,这将是编辑。 previously我会使用 ListView.View 然后把 GridView控件在那里的列。但现在看来, ListView.View 是德precated就像 GridView.Columns

So I am trying to move a desktop program i made to an app for Windows 8.1 using Visual Studio 2013. Datagrid was deprecated for this release so I am trying to translate those over to a ListView. I previously used ListViews in other desktop applications, but it looks like a lot has changed. The problem I am having is populating my ListView from my database. I am connecting through a WCF Service and stepping through the code, I can see I am getting the right data, I just cant get it to appear in my ListView. My preferred end result would be a 'listview' with 3 columns of information which will be editable. Previously I would use ListView.View and then put a GridView in there for the columns. But it appears ListView.View is deprecated just like GridView.Columns.

下面是我的XAML的的ListView

here is my xaml for the ListView

<ListView x:Name="lvInventory" Grid.Row="2" Style="{StaticResource listViewStyle}" ItemsSource="{Binding}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Height="200"  Width="200">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock x:Name="tbName" Text="{Binding InventoryName}" Width="200" Foreground="#FF0E0D0D" />
                        <TextBox x:Name="tbQty" Grid.Column="1"/>
                        <TextBox x:Name="tbType" Grid.Column="2"/>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

在我的codebehind我分配我的列表视图的的ItemsSource。

In my codebehind I am assigning the itemssource of my listview.

        VMInventory inventory = new VMInventory();            
        inventory.GetList();
        lvInventory.ItemsSource = inventory;

VMInventory 是我的视图模型我在哪里从 WCF服务让我的数据键,看起来像:

VMInventory is my ViewModel where I am getting my data from the WCF service and that looks like:

 public async Task GetList()
    {

            this.connection = new InventoryModelEntities(new Uri(url));
            var filteredList = from o in connection.Inventory
                               where o.Have == false
                               select o;
            var query = await Task.Factory.FromAsync((filteredList as DataServiceQuery).BeginExecute(null, null),
                (result) => (filteredList as DataServiceQuery).EndExecute(result)) as IEnumerable<Aurora.InventoryService.Inventory>;

            this.inventoryList = query.ToList();
            this.currentItem = 0;
            this.onPropertyChanged("Current");
            this.IsAtStart = true;
            this.IsAtEnd = (inventoryList.Count == 0);
}

最后一个侧面说明,我是能够将文本框添加到电网,当我的DataBind 文本={结合Current.InventoryName}我能够成功绑定。

One last side note, I was able to add a textbox to the Grid and when I DataBind it to text="{Binding Current.InventoryName}" I am able to successfully bind it.

推荐答案

如果我正确地理解你的用户界面是没有得到与值什么都你的视图模型添加更新,但如果你在UI添加一些值,它是在视图模型反映

If i understand correctly your UI is not getting updated with values what ever your adding in ViewModel, but if you add some value in UI it is reflecting in the ViewModel.

如果是这样的话,使用ObserableCollection而不是列表,如果你的每一次创建列表,然后你在你的视图模型来实现INotifyPropertyChanged。

If that is the case, the use ObserableCollection instead of list, and if your creating list every time, then you have to implement INotifyPropertyChanged in your ViewModel.

如果你所做的这一切,但仍然没有更新的话,你的创造ASY任务,这是不是一个UI线程列表。如果您想更新从非UI线程的UI,然后利用更新使用Dispatcher的UI。你可以找到很多例子使用Dispatcher更新从非UI线程的UI

If you have done all this but still it is not updating then, your creating the list in asy Task, which is not a UI thread. If you want to update a UI from a non-Ui thread, then use update the UI using Dispatcher. You can find lot of examples to update the UI from non-UI thread using dispatcher

这篇关于ListView控件数据绑定的Windows 8.1应用程序商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆