如何在通过 xaml UI 更新数据后刷新数据透视项中的数据? [英] How to refresh the data in pivot item after updating data through xaml UI?

查看:15
本文介绍了如何在通过 xaml UI 更新数据后刷新数据透视项中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在开发 Windows Phone 8 应用程序,我遇到了一个问题,我正在我的数据透视项中加载一些数据,如果用户点击用户控件打开,我通过用户控件修改数据.数据已成功保存到数据库中,但我的数据透视项未立即更新.我正在使用可观察的集合,如下所示.

Hello all i am working on windows phone 8 app, i am facing a issue, i am loading some data in my pivot item and if user tap a user control opens and i modify the data through user control. Data is saving into the database successfully but my pivot item is not updating immediately. i am using observable collection as following.

我在 mypivot.xaml.cs 文件中使用了如下所示的 ObservableCollection

ObservableCollection i used like following in mypivot.xaml.cs file

ObservableCollection<MyWrapper> saveinfo = new ObservableCollection<MyWrapper>();
public ObservableCollection<MyWrapper> savedWordBankCollection
{ get { return saveinfo; } }

//MyWrapper class structure

public class MyWrapper: INotifyPropertyChanged
{
    private string desc;
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyChange(PropertyChangedEventArgs e)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, e);
    }
    public string Name { get; set; }
    public string NameDescription
    {
        get { return desc; }
        set
        {
            desc = value;
            NotifyChange(new PropertyChangedEventArgs("NameDescription"));
        }
    }
    public string NameId { get; set; }   
    public string NameLocId { get; set; }
}

现在,我正在将数据加载到数据透视页面中的数据透视项中

Now as following i am loading data into my pivot item in pivot page

private void LoadWordbank()
{
        List<MysecondWrapper> dbData = helper.FetchAllName(thisApp.CurrentName.Id);
    if (dbData.Count != 0)
    {
        foreach (MySerconWrapper item in dbData)
        {
            saveinfo.Add(new MyWrapper { NameLocalId = item.Id.ToString(), Name= item.Name, NameDescription = item.Description, NameId = thisApp.CurrentName.Id});
        }
    }
}

mypivot.xaml 如下.我不是在写完整的代码,而是我如何分配我显示的属性.

mypivot.xaml as follwoing. i am not writing full code but how i have assigned the attributes that i am showing.

 <TextBlock x:Name="wordbankStored" Grid.Column="0" Grid.Row="0" Text="{Binding Name}"/>                               
 <Button x:Name="btnWordDescription" Grid.Row="1" Grid.Column="0" Content="{Binding NameDescription}" 
Tag="{Binding}" Click="btnNameDescription_Click"/>

在上面的文本块中我尝试过:

In above textblocks i tried:

Content="{Binding NameDescription, Mode=TwoWay}"

但它没有用所以我已经删除了.在 btnNameDescription_Click 上,我的用户控件打开,我可以将数据保存在 wp8 的本地数据库中,但它不会立即显示在我的数据透视表中.请给我建议什么以及怎么做?我错在哪里.需要帮助.

but it didn't work so i have removed. on btnNameDescription_Click my user control opens and i can save data in my local db of wp8 but it does not show immediately in my pivot. Please give me suggession what and how to do ? where i am wrong. need help.

推荐答案

我已经做了,首先不需要刷新页面,observable集合可以自动完成.我的 observableCollection 是 saveInfoCollection.

I have done, first of all no need to refresh the page, observable collection can do it automatically. my observableCollection is saveInfoCollection.

可观察集合有三种可能性

there are three possiblities with the observable collection

1) 从 observable 集合中删除一个项目.

1) deletion a item from observable collection.

2) 修改 observable 集合中的一个项目.

2) Modifying a item in observable collection.

3) 在 observable 集合中添加一个项目.

3) Add a item in observable collection.

说明

1) 在第一种情况下,当我从 observable 集合中删除项目时,我将使用 observable 集合的 remove 方法,如下所示

1) In first case when i will delete the item from the observable collection i will use the remove method of the observable collection like following

//savedData is my observableCollection name.
savedData.Remove(selected);

2) 在第二种情况下,当我将修改 observable 集合中的项目时,在这里您将看到 observable 集合的神奇之处,我在 Tag 属性的帮助下获取项目对象,因此我将更新我的数据库我的 observable 集合会自动更新.

2) In second case when i will modify the item from the observable collection, here you will see the magic of the observable collection, I am taking the item object with the help of Tag property, so as i will update my database it my observable collection will automatically update.

3) 在这种情况下,您可以将新的数据对象添加到 observable 集合中,它会自动更新 observable 集合.

3) In this case you can add new data object into the observable collection, and it will automatically update the observable collection.

如果您使用的是 observableCollection,则无需刷新页面.这就是 ViewModel 的神奇之处.

If you are using the observableCollection than no need to refresh the page. It is the magic of ViewModel.

这篇关于如何在通过 xaml UI 更新数据后刷新数据透视项中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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