I've found very strange behavior.
A simple project contains the window with RadGridView. ItemsSource is binded to ViewModel.Rows where Rows is ObservableCollection.
I fill rows inside Window Loaded event.
RadGridView doen't updated if I don't use Rows.Clear() before Rows.Add().
Can you explain this?
Here is xaml:
01.
<
Window
x:Class
=
"TelerikWpfApp1.MainWindow"
03.
xmlns:x
=
"http://schemas.microsoft.com/winfx/2006/xaml"
04.
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
05.
xmlns:local
=
"clr-namespace:TelerikWpfApp1"
06.
Loaded
=
"Window_Loaded"
>
07.
<
Window.Resources
>
08.
<
local:ViewModel
x:Key
=
"vm"
/>
09.
</
Window.Resources
>
10.
<
Grid
DataContext
=
"{Binding Mode=OneWay, Source={StaticResource vm}}"
>
11.
<
telerik:RadGridView
ItemsSource
=
"{Binding Rows}"
/>
12.
</
Grid
>
13.
</
Window
>
And code behind:
01.
using
System.Collections.ObjectModel;
02.
using
System.Windows;
03.
04.
namespace
TelerikWpfApp1
05.
{
06.
public
partial
class
MainWindow : Window
07.
{
08.
public
MainWindow()
09.
{
10.
InitializeComponent();
11.
}
12.
13.
private
void
Window_Loaded(
object
sender, RoutedEventArgs e)
14.
{
15.
var rows = ((ViewModel)FindResource(
"vm"
)).Rows;
16.
// to make it work uncomment the next row
17.
//rows.Clear();
18.
rows.Add(
new
Row { Name =
"Name1"
, Column1 =
"value1_1"
});
19.
rows.Add(
new
Row { Name =
"Name2"
, Column1 =
"value2_1"
});
20.
}
21.
}
22.
23.
class
Row
24.
{
25.
public
string
Name {
get
;
set
; }
26.
public
string
Column1 {
get
;
set
; }
27.
}
28.
29.
class
ViewModel
30.
{
31.
public
ObservableCollection<Row> Rows {
get
; } =
new
ObservableCollection<Row>();
32.
}
33.
}