Hi there,
I must say I am generally impressed with quality of the RAD controls. However I think I found a bug in the RadGridView control – Binding to SelectedItem does not have any effect:
<UserControl
x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SilverlightApplication1"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<UserControl.DataContext>
<local:TestViewModel />
</UserControl.DataContext>
<Grid x:Name="LayoutRoot" >
<telerikGrid:RadGridView AutoGenerateColumns="True"
ItemsSource="{Binding List}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
</telerikGrid:RadGridView>
<!— MS grid works fine -->
<!--<data:DataGrid AutoGenerateColumns="True"
ItemsSource="{Binding List}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
</data:DataGrid>-->
</Grid>
</UserControl>
ViewModel:
public class TestViewModel : INotifyPropertyChanged
{
public TestViewModel()
{
var list = from i in Enumerable.Range(1, 10)
select i.ToString();
List = list.ToList();
SelectedItem = List[0];
}
/// <summary>
///
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
///
/// </summary>
/// <param name="property"></param>
protected void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
private IList<string> list;
/// <summary>
///
/// </summary>
public IList<string> List
{
get
{
return list;
}
private set
{
this.list = value;
this.OnPropertyChanged("List");
}
}
private string selectedItem;
/// <summary>
///
/// </summary>
public string SelectedItem
{
get
{
return this.selectedItem;
}
set
{
// this will not get invoked when used with telerik RadGridView
this.selectedItem = value;
this.OnPropertyChanged("SelectedItem");
}
}
}
Using the same code with MS data grid works fine. I have tried different versions of Telerik controls with no luck:
· 2009.2.701.1020
· 2009.2.720.1020
· 2009.2.724.1020 (latest dev build)
I know I can solve the problem by using code behind but I would prefer to bind view to underlying view model. I saw few people reporting the same bug in other WPF/Silverlight Telerik controls.
Kind Regards,
Milosz