or
<Window x:Class="WpfApplication6.MainWindow"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=Employees}" x:Key="employees"/>
</Window.Resources>
<Grid>
<telerik:RadGridView ItemsSource="{Binding Source={StaticResource employees}}" Margin="12,12,0,120" />
<ListBox ItemsSource="{Binding Source={StaticResource employees}}" Margin="12" Height="102" VerticalAlignment="Bottom" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="8" />
<TextBlock Text="{Binding Id}" Margin="8" />
<TextBlock Text="{Binding Class}" Margin="8" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
And codebehind:namespace WpfApplication6{ public partial class App : Application { public ObservableCollection<Employee> Employees { get; set; } private void Application_Startup(object sender, StartupEventArgs e) { Employees = new ObservableCollection<Employee>(); Employees.Add(new Employee() { Name = "Alice", Id = 1 }); Employees.Add(new Employee() { Name = "Bob", Id = 2 }); Employees.Add(new Employee() { Name = "Charlie", Id = 3 }); new MainWindow().Show(); } } public class Employee { public string Name { get; set; } public int Id { get; set; } public virtual string Class { get { return "Base"; } } } public class ExtendedEmployee : Employee { public override string Class { get { return "Extended"; } } }}Employees.Add(new ExtendedEmployee() { Name = "Alice", Id = 1 });Employees.Add(new ExtendedEmployee() { Name = "Bob", Id = 2 });Employees.Add(new ExtendedEmployee() { Name = "Charlie", Id = 3 });Employees.Add(new Employee() { Name = "Alice", Id = 1 });Employees.Add(new Employee() { Name = "Bob", Id = 2 });Employees.Add(new ExtendedEmployee() { Name = "Charlie", Id = 3 });<Window.Resources> <Style x:Key="itemStyle" TargetType="telerik:RadTreeViewItem"> <Setter Property="IsSelected" Value="{Binding Path=Select, Mode=TwoWay}" /> <Setter Property="IsExpanded" Value="{Binding Path=Expand, Mode=TwoWay}" /> <Setter Property="IsInEditMode" Value="{Binding Path=EditMode, Mode=TwoWay}" /> </Style> </Window.Resources> <DockPanel> <StackPanel Orientation="Vertical" DockPanel.Dock="Bottom"> <Button Command="{Binding AddCommand}">Add Person</Button> <Button Command="{Binding DeleteCommand}">Delete current</Button> </StackPanel> <telerik:RadTreeView IsEditable="True" ItemsSource="{Binding Persons}" ItemContainerStyle="{StaticResource itemStyle}" SelectedItem="{Binding Path=Current, Mode=TwoWay}"> <telerik:RadTreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Childs}"> <TextBlock Text="{Binding Name}"/> </HierarchicalDataTemplate> </telerik:RadTreeView.ItemTemplate> </telerik:RadTreeView> </DockPanel>Persons.Add(new PersonViewModel(new Model.Person("New person", new string[]{})) { Select=true, EditMode=true}); if (Current != null) { if (Current.Parent != null) Current.Parent.Childs.Remove(Current); else person.Remove(Current); // Not the role to viewmodel to select another element }GridSelectedZipCodes.ItemsSource = ZipGeoCodeService.GetForZipPart((string)item.Header, (float)_selectedDealer.Latitude, (float)_selectedDealer.Longitude, (float)_selectedDealer.MaxDistance);static public List<ZipGeoCode> GetForZipPart(string zippart, float latitude, float longitude, float distance)private void SelectZipCodes() { IsLoading = true; foreach (ZipGeoCode _item in GridSelectedZipCodes.Items) { if (_dealerZipCodes.Find(delegate(ZipGeoCode zgc) {return zgc.ID == _item.ID; }) != null) { GridSelectedZipCodes.SelectedItems.Add(_item); } } IsLoading = false; } SelectionChangeEventArgs
would be great.private void GridSelectedZipCodes_SelectionChanged(object sender, SelectionChangeEventArgs e) { if (!(IsLoading)) { //remove all items foreach (ZipGeoCode _item in GridSelectedZipCodes.Items) { if (_dealerZipCodes.Find(delegate(ZipGeoCode zgc) { return zgc.ID == _item.ID; }) != null) { _dealerZipCodes.Remove(_item); } } foreach (ZipGeoCode _item in GridSelectedZipCodes.SelectedItems) { _dealerZipCodes.Add(_item); } } }#region Deklarationenprivate ObservableCollection<RWF_GUI_TransferItems> _Items;/// <summary>/// Enthält alle Elemente die in dem GridView dargestellt werden./// </summary>public ObservableCollection<RWF_GUI_TransferItems> Items{ get { return _Items; } set { _Items = value; this.ValueChanged("Items"); }}private ICollectionView _ItemsView;/// <summary>/// View zur Überwachtung des aktuellen Grid-Items/// </summary>public ICollectionView ItemsView{ get { return _ItemsView; } set { _ItemsView = value; this.ValueChanged("ItemsView"); }}private RWF_GUI_TransferItems _AktuelleGridAuswahl;/// <summary>/// Aktuelle Gridzeile/// </summary>public RWF_GUI_TransferItems AktuelleGridAuswahl{ get { return _AktuelleGridAuswahl; } set { _AktuelleGridAuswahl = value; this.ValueChanged("AktuelleGridAuswahl"); }}public MainViewModel(){ this.Items = new ObservableCollection<RWF_GUI_TransferItems>(); this.ItemsView = CollectionViewSource.GetDefaultView(this.Items); this.ItemsView.CurrentChanged += new EventHandler(OnCurrentItemChanged);}void OnCurrentItemChanged(object sender, EventArgs e){ this.AktuelleGridAuswahl = (RWF_GUI_TransferItems)this.ItemsView.CurrentItem;}<telerik:RadGridView ItemsSource="{Binding ItemsView}" RowHeight="25" CanUserFreezeColumns="False" AutoGenerateColumns="False" ShowColumnFooters="true" x:Name="GridViewMain" IsSynchronizedWithCurrentItem="True" IsEnabled="{Binding AtWork, Converter={StaticResource NegateBoolConverter}}">OnCurrentItemChanged-Event is only being raised on startup (this.ItemsView.CurrentItem is null at this moment).