I am using ICollectionView
to bind wpfdatagrid
.ICollectionView
source is observable collection. i update the observable collection 5 seconds once. but the collection is modified, but it is not updating to DataGrid
.
public ICollectionView CollectionView { get; set; }
public ObservableCollection<AgentListEntryViewModel> AgentsViewModel
{
get { return _agentsViewModel; }
set { _agentsViewModel = value; }
}
i set the value to collection view below.
this.CollectionView = new ListCollectionView(this.AgentsViewModel);
this.CollectionView.Filter = this.SearchAgents;
in xaml
, I bind observable collection to data grid.
I have implemented INotifyPropertyChanged
in type of ObservableCollection i.e., in AgentListEntryViewModel
private void LoadAgentComponents(List<AgentStateInfo> agentStateInfos = null)
{
foreach (AgentStateInfo agentStateInfo in agentStateInfos)
{
AgentListEntryViewModel agentEntry = this.AgentsViewModel.SingleOrDefault(agent => agent.AgentStateInfo.AgentId == agentStateInfo.AgentId);
if (agentEntry != null)
{
agentEntry.UpdateAgentEntry(agentStateInfo);
}
}
this.OnPropertyChanged("AgentsViewModel");
}
the above method i am using to update the observable collection.
<DataGrid VerticalAlignment="Stretch" Grid.Row="2" Grid.ColumnSpan="3" Background="{StaticResource ControlLightColor}" BorderBrush="LightGray" BorderThickness="2" HorizontalAlignment="Stretch"
IsReadOnly="True"
GridLinesVisibility="Vertical"
VerticalGridLinesBrush="LightGray"
CanUserAddRows="False"
CanUserResizeRows="False"
SelectionMode="Single"
AutoGenerateColumns="False"
HeadersVisibility="Column"
SnapsToDevicePixels="True"
VerticalContentAlignment="Center"
ItemsSource="{Binding AgentsViewModel}"
SelectedItem="{Binding SelectedAgentComponent}">
</DataGrid>
the above xaml i used to bind to DataGrid.
but The datagrid not updated. can anyone help me .