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

查看:124
本文介绍了通过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.

推荐答案

我已经完成了,首先不需要刷新页面,可观察的集合可以自动完成.我的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)从可观察的集合中删除一个项目.

1) deletion a item from observable collection.

2)修改可观察集合中的项目.

2) Modifying a item in observable collection.

3)在可观察的集合中添加一个项目.

3) Add a item in observable collection.

说明

Explaination

1)在第一种情况下,当我从可观察的集合中删除项目时,我将使用可观察的集合的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)在第二种情况下,当我从可观察的集合中修改项目时,在这里您将看到可观察的集合的魔力,我将在Tag属性的帮助下获取该项目对象,以便我将更新我的数据库它的可观察集合将自动更新.

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)在这种情况下,您可以将新的数据对象添加到可观察的集合中,它将自动更新可观察的集合.

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天全站免登陆