0

As can be seen in the SimpleMDI Caliburn Micro project there are some conventions that bind the selectionEvent in tabControls to the ActivateItem in a Conductor. I can't really see any mention of what this event might be.

However when you have a control that doesn't fullfill these convention I'm lost on how to manage them myself.

I have a Telerik RadTreeView that I want to manage with a conductor to be able to load on demand the childs of nodes (via WCF call).

Here is where I am at:

<telerik:RadTreeView x:Name="Items"
                     cal:Message.Attach="[Event Selected] = [ActivateItem($dataContext)]"  />

Passing $dataContext is wrong because that way he passes the Conductor itself, $SelectedItem returns null.

So my rather simple question is threefold.

1) If RadTreeView is a Selecetor why doesn't the basic CM convention work with it,

2) What event should I use to call ActiveItem

3) What could I pass in.

Ingó Vals
  • 4,788
  • 14
  • 65
  • 113
  • Are you displaying hierarchical data? – Derek Beattie Jul 09 '12 at 16:52
  • I've actually changed how it's supposed to work. Yes I wanted to display hierarchical but it would all implement IActivate thing. Problems was connecting a event in the treeview with the activation logic of the conductor. I had no idea how to pass the selected items as a parameter. – Ingó Vals Jul 09 '12 at 17:46

1 Answers1

1

This might help understand the different approaches to doing treeviews and mvvm.

I was using the RadTreeView also and I ended up sending the events to the ViewModel that hosted the Items collection of TreeViewItemViewModel. When an action/event, for example, Edit, was sent to the MainViewModel, I had a method like:

 public void Edited(object sender, RadTreeViewItemEditedEventArgs e)
        {
            var treeViewItemViewModel = e.NewValue as IEditable;
            if (treeViewItemViewModel == null) return;

            treeViewItemViewModel.EndEdit();
        }

So this worked at any level in the tree and also worked for having different behaviors, checking to see if the interface for different things was implemented.

xaml for the RadTreeView

 <telerik:RadTreeView x:Name="MyTree"
                                     Grid.Row="1"
                                     Margin="0,20,0,0"
                                     VerticalAlignment="Stretch"
                                     FontSize="16"
                                     FontFamily="{StaticResource MainFontFamily}"
                                     ItemsSource="{Binding Children, Mode=TwoWay}"
                                     ItemTemplate="{StaticResource HierarchicalDataTemplate}"
                                     ItemEditTemplateSelector="{StaticResource ItemEditTemplateSelector}"
                                     ItemEditTemplate="{x:Null}"
                                     IsLoadOnDemandEnabled="True"
                                     IsEditable="True"
                                     IsDragDropEnabled="True"
                                     DropExpandDelay="00:00:01"
                                     telerik:TextSearch.TextPath="ItemId"
                                     PathSeparator="|"
                                     cal:Message.Attach="
                                    [Event LoadOnDemand] = [Action LoadOnDemand($eventArgs)];
                                    [Event PreviewDragStarted] = [Action PreviewDragStarted($source,$eventArgs)];
                                    [Event PreviewDragEnded] = [Action PreviewDragEnded($source,$eventArgs)];
                                    [Event DragEnded] = [Action DragEnded($source,$eventArgs)];
                                    [Event Edited] = [Action Edited($source,$eventArgs)];
                                    [Event EditCanceled] = [Action EditCanceled($source,$eventArgs)]"/>
Derek Beattie
  • 9,429
  • 4
  • 30
  • 44
  • Well Caliburn.Micro should help you avoid all mess like this. So you could just create a normal method and pass something as a parameter through. The parameter should be the item I just selected, but I was hoping I could say that in the cal:Message.Attach – Ingó Vals Jul 10 '12 at 14:24
  • I am using Message.Attach. ` [Event Edited] = [Action Edited($source,$eventArgs)];` I edited to show the xaml for the TreeView. – Derek Beattie Jul 10 '12 at 15:17
  • Let me know if you have any more questions, I can provide a better example. – Derek Beattie Jul 10 '12 at 18:19