private void OnTopicNewHelper(ItemsControl parentItem) { TopicModel parentTopic = (TopicModel)parentItem.DataContext; IPresentationList<TopicModel> presentationList = (IPresentationList<TopicModel>)parentTopic.Topics; IBindingList list = (IBindingList)presentationList; using (ITransaction t = _model.TransactionContext.BeginTransaction()) { TopicModel topic = (TopicModel)list.AddNew(); topic.Title = "New topic"; using (Validator v = new TopicValidator(topic.RowView)) { TopicWnd wnd = new TopicWnd(topic, v); wnd.Owner = this; if (wnd.ShowDialog() ?? false) { t.Success = true; TreeViewItem item = (TreeViewItem)parentItem.ItemContainerGenerator.ContainerFromItem(topic); topic = (TopicModel)item.DataContext; topic.NotifyPropertyChanged(); item.Focus(); } } } }
private void OnTopicEdit(Object sender, ExecutedRoutedEventArgs e) { TreeView tree = (TreeView)e.Source; TreeViewItem item = (TreeViewItem)tree.Tag; TopicModel model = (TopicModel)item.DataContext; using (ITransaction t = _model.TransactionContext.BeginTransaction()) { using (Validator v = new TopicValidator(model.RowView)) { TopicWnd wnd = new TopicWnd(model, v); wnd.Owner = this; if (wnd.ShowDialog() ?? false) { t.Success = true; item.Focus(); model.NotifyPropertyChanged(); } } } }