Hi,
I have a simple project with a RadTreeView and two button (add/delete) bind to ICommand from my model.
1 When I try to add an item my AddCommand add a item in my binding collection
With this way the RadTreeViewItem is well editing but fill with text "RadTreeSample.ViewModel.PersonViewModel" and not "New Person". If i change EditMode=true to EditMode=false the item is well selected and well filled and i can edit correctly after. How to enable EditMode correctly ?
2 When i delete an item it will be fun if previous item become selected. First idea was to change the selected item in the DeleteCommand BUT i think that it's not the job of the ViewModel, it's typically a job for the View. How can i implement this ? The goal is that View and ViewModel have no reference between them.
I have a simple project with a RadTreeView and two button (add/delete) bind to ICommand from my model.
<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>1 When I try to add an item my AddCommand add a item in my binding collection
Persons.Add(new PersonViewModel(new Model.Person("New person", new string[]{})) { Select=true, EditMode=true}); 2 When i delete an item it will be fun if previous item become selected. First idea was to change the selected item in the DeleteCommand BUT i think that it's not the job of the ViewModel, it's typically a job for the View. How can i implement this ? The goal is that View and ViewModel have no reference between them.
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 }