“刷新"带有用于WP7的Mvvm-light工具包的数据透视控制 [英] "Refresh" Pivot Control with Mvvm-light toolkit for WP7

查看:65
本文介绍了“刷新"带有用于WP7的Mvvm-light工具包的数据透视控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Xaml中有一个透视控件:

I have in my Xaml a pivot control :

    <controls:Pivot ItemsSource="{Binding ObjectList}">
        <controls:Pivot.HeaderTemplate>
            <DataTemplate>
                <TextBlock />
            </DataTemplate>
        </controls:Pivot.HeaderTemplate>
        <controls:Pivot.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Value1}" />
                    <TextBlock Text="{Binding Value2}" />
                </StackPanel>
            </DataTemplate>
        </controls:Pivot.ItemTemplate>
    </controls:Pivot>    

我的ViewModel是:

My ViewModel is :

public class MyObject
{
    public string Value1 { get; set; }
    public string Value2 { get; set; }
}

public class MyViewModel : ViewModelBase
{
    public const string ObjectListPropertyName = "ObjectList";
    private ObservableCollection<MyObject> _objectList;
    public ObservableCollection<MyObject> ObjectList
    {
        get
        {
            return _objectList;
        }

        private set
        {
            if (_objectList == value)
                return;
            _objectList = value;
            RaisePropertyChanged(ObjectListPropertyName);
        }
    }

    private DispatcherTimer timer;

    public MyViewModel()
    {
        ObservableCollection<MyObject> collection = new ObservableCollection<MyObject>
                          {
                              new MyObject {Value1 = "One"},
                              new MyObject {Value1 = "Two"},
                              new MyObject {Value1 = "Tree"}
                          };
        ObjectList = collection;
        timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2)};
        timer.Tick += timer_Tick;
        timer.Start();
    }

    void timer_Tick(object sender, EventArgs e)
    {
        foreach (MyObject myObject in _objectList)
        {
            myObject.Value2 = "Something";
        }
        Application.Current.RootVisual.Dispatcher.BeginInvoke( () => RaisePropertyChanged(ObjectListPropertyName));
    }
}

到达timer_tick时,我认为枢轴控件将使用新值刷新...但是我看不到任何更改.

When the timer_tick is reached, I supposed the pivot control to refresh with the new values ... but I can't see any changes.

我想念什么?

预先感谢您的帮助

推荐答案

我猜测可能是在不更新列表本身的情况下更新列表成员的问题.引发属性更改事件时-适用于整个集合.尽管成员已更改,但是该集合仍指向其自身的平等引用.

I'm guessing that possibly updating the members of the list without updating the list itself is the problem. When you raise the property changed event - it is for the entire collection. The collection is still pointing to an equal reference of itself, despite the fact that the members have changed.

尝试在设置器中放置一个断点,并查看是否触发了属性更改事件.

Try placing a breakpoint in the setter and see if the property changed event is fired.

这篇关于“刷新"带有用于WP7的Mvvm-light工具包的数据透视控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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