开发者

Silverlight DataGrid column bind to object dont refresh

开发者 https://www.devze.com 2023-03-07 23:05 出处:网络
I have bound DataGrid to IEnumerable< Object >. Object has EntityCollection< Access > property and it is name Accesses. Then inI put this

I have bound DataGrid to IEnumerable< Object >. Object has EntityCollection< Access > property and it is name Accesses. Then in I put this

    <sdk:DataGridTextColumn
                 Binding="{Binding Path=Accesses, Converter={StaticResource AccessesToTextConverter}}"
                 Header="Access"/>

All work fine. But when I add Acce开发者_C百科ss object to Accesses in my viewmodel DataGrid does nor refresh. Why? :)


You are adding items to a IEnumerable collection which the datagrid will not do anything with. Your collection you bind to must implement INotifyCollectionChanged for the datagrid to automatically update.

If you are using a collection which holds your RIA services results as a property in an object collection that gets assigned as your ItemsSource, make sure you hookup the CollectionChanged event to the PropertyChanged event of your object like so:

    public EntityCollection accesses;
    public EntityCollection Accesses
    {
        get { return accesses; }
        set
        {
            OnPropertyChanged("Accesses");
            value.CollectionChanged += (sender, e) => { OnPropertyChanged("Accesses"); };
            accesses = value;
        }
    }


You need to specify TwoWay for the mode in order to update the UI from the code for one thing:

<sdk:DataGridTextColumn                 
    Binding="{Binding Path=Accesses, Mode=TwoWay, Converter={StaticResource AccessesToTextConverter}}"  Header="Access"/>
0

精彩评论

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