这是一个例子:
XAML
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="Window1">
<Grid>
<telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}">
<telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition />
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.HierarchyChildTemplate>
<DataTemplate>
<telerik:RadGridView ItemsSource="{Binding Items}" Loaded="RadGridView_Loaded" />
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
</telerik:RadGridView>
</Grid>
C#
using System.Windows;
using System.Linq;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DataContext = from i in Enumerable.Range(0, 10)
select new
{
ID = i,
Items = from j in Enumerable.Range(0, 10)
select new
{
ID = j,
}
};
}
private void RadGridView_Loaded(object sender, RoutedEventArgs e)
{
RadGridView1.SelectedItem = ((FrameworkElement)sender).DataContext;
}
}
}