I'm facing an issue in datagrid binding using mvvm on two different places. Headers of my datagrid (xaml) is:
<DataGrid Grid.Row="0" Grid.Column="0" AlternationCount="2" Background="White" RowHeight="28" HorizontalGridLinesBrush="Lavender" VerticalGridLinesBrush="Lavender"
VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsSynchronizedWithCurrentItem="True"
ScrollViewer.CanContentScroll="True" Name="MainGrid" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Visible"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserAddRows="False"
CanUserDeleteRows="False" CanUserResizeRows="True" ItemsSource="{Binding Path=Configurations, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
which clealy says
ItemsSource="{Binding Path=Configurations, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
In my viewmodel:
public ObservableCollection<ViewerConfiguration> Configurations
{
get { return m_tasks; }
set { m_tasks = value; OnPropertyChanged("Configurations"); }
}
The data that in the list is shown properly on the view but the problem is with the insert and delete (even it updates successfully). I have a function which inserts an item in the Configuration object
private void Refresh()
{
List<ViewerConfiguration> newlyAddedFiles = GetConfigurations();
foreach (ViewerConfiguration config in newlyAddedFiles)
{
Configurations.Add(config);
}
}
and removes like:
Configurations.Remove(configuration);
The problem is really with the insert and delete. On debugging there is no exception and it successfully deletes from collection too but UI doesn't get a notification. Any guesses why is this behavior?
Additionally: I have an event trigger just under the datagrid:
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RenderPdf}" CommandParameter="{Binding SelectedItem, ElementName=MainGrid}"></i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
and I'm calling Refresh function from the constructor of ViewModel just to see if it works or not.
Configuration
property. – T McKeown