开发者

Silverlight ObservableCollection dependency properties are not updated in design mode

I use a dependency property of type ObservableCollection<> in my control. I want to automatically change content display in my control while editing XAML code. I write such a code:

public class RowInfoCollection : ObservableCollection<RowInfo>
{
}

//... here my control class
    public static readonly DependencyProperty RowDataProperty = 
        DependencyProperty.Register("RowData", typeof(RowInfoCollection), typeof(VisiGrid), 
        new PropertyMetadata(new RowInfoCollection(), RowDataChangedCallback));

    public RowInfoCollection RowData
    {
        get
        {
            return (RowInfoCollection)base.GetValue(RowDataProperty);
        }
        set
        {
            base.SetValue(RowDataProperty, value);
        }
    }

    private static void RowDataChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        VisiGrid vg = d as VisiGrid;
        vg.rowData = (RowInfoCollection)e.NewValue;
        vg.rowData.CollectionChanged += vg.rowData_CollectionChanged;
        // Some application specific logic skipped
    }

    void rowData_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        rowData = RowData;
        switch (e.Action)
        {
            // Skipped
        }
    }

When in run time, everything works ok. But when I change the property value in VS2010 designer there are some problems. When I completely remove value or insert it instead of empty VS' designer successfully refreshes display of my control. But when I add or remove collection items one at a time there's no change. When I build project the display updates (in fact, the designer reloads).

When I looked under debugger I saw that when in design mode it successfully calls my callback function when the collection is totally removed or inserted but does not fire CollectionChanges event when it is changed partially.

How should I force VS designer to track collection changes and fire ev开发者_如何转开发ents?

Thank you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜