Silverlight DataGrid column bind to object dont refresh
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"/>
精彩评论