11 Answers, 1 is accepted
You can add a Class EventHandler that will select an item on MouseRight click like so:
static Window1() |
{ |
EventManager.RegisterClassHandler(typeof(RadTreeViewItem), |
Mouse.MouseDownEvent, new MouseButtonEventHandler(OnTreeViewItemMouseDown), false); |
} |
public static void OnTreeViewItemMouseDown(object sender, MouseButtonEventArgs e) |
{ |
var treeViewitem = sender as RadTreeViewItem; |
if (e.RightButton == MouseButtonState.Pressed) |
{ |
treeViewitem.IsSelected = true; |
e.Handled = true; |
} |
} |
As for your second question:
Currently, you can implement drag drop across TreeViews using the standard DragDrop in WPF but there is very little help on the internet on how to use it.
We are planning to port our Silverlight DragDrop for WPF for the Q2 release of the controls, then you will be able to use drag/drop across controls.
Hopefully this will work for you,
Kind regards,
Miroslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
<telerik:RadTreeView.ItemTemplate x:Uid="TreeItemTemplate" >
<HierarchicalDataTemplate ItemsSource="{Binding Children}" x:Name="dataTemplate" >
<StackPanel Orientation="Horizontal" >
<Image x:Name="ImgTreeNode" Height="16" Width="16" Margin="0,0,2,0"
Source="{Binding Path=ImageKey}"/>
<WrapPanel>
<WrapPanel>
<Image x:Name="ImgTreeNodeSeverity" Margin="0,0,2,0" Height="16" Width="16"
Stretch="UniformToFill" StretchDirection="DownOnly" HorizontalAlignment="Left"
Source="{Binding src" ClipToBounds="True" SnapsToDevicePixels="True" />
</WrapPanel>
<!--Loaded="ImgTreeNode_Loaded"-->
<TextBlock x:Name="txtObjName" Text="{Binding DisplayName}"/>
</WrapPanel>
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding src}" Value="FaultNormal">
<Setter TargetName="ImgTreeNodeSeverity" Property="Image.Source" Value="{Binding null}"/>
<Setter TargetName="ImgTreeNodeSeverity" Property="Image.Visibility" Value="Collapsed"/>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>
Now when i use the code
static Window1() |
{ |
EventManager.RegisterClassHandler(typeof(RadTreeViewItem), |
Mouse.MouseDownEvent, new MouseButtonEventHandler(OnTreeViewItemMouseDown), false); |
} |
public static void OnTreeViewItemMouseDown(object sender, MouseButtonEventArgs e) |
{ |
var treeViewitem = sender as RadTreeViewItem; |
if (e.RightButton == MouseButtonState.Pressed) |
{ |
treeViewitem.IsSelected = true; |
e.Handled = true; |
} |
} |
treeViewitem i.e. it is null and i cant show the context menu there.
I am not able to use the contextMenuOpening as the break point there is never hit.
Please suggest the solution. Any code will be helpful.
Thanks and regards
Prashant
I have created a sample project according to the HierarchicalDataTemplate you have provided. I did not experience any issues while testing the project.
Please let me know if there is something I am missing.
Kind regards,
Kiril Stanoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
The shared sample is working fine.
But now we are facing the issue while using tree control in the two different windows (different class files)of the same application.
Issue: Let say "Window1" and "Window2" are two windows (different class files) and I want to show the context menu on the type of item selected in the tree control (treeViewItem) of "Window1" and dont want to show context menu on "Window2". Now as we have registered the "MouseDownEvent" on tree view item
"EventManager.RegisterClassHandler(typeof(RadTreeViewItem),
Mouse.MouseDownEvent, new MouseButtonEventHandler(OnTreeViewItemMouseDown), false);"
in "Windows1", "OnTreeViewItemMouseDown" function will get called when mouse is down on tree view item contained in "Window1". But this function will also get called when mouse is down on tree view item of "Windows2".
How can we registere the mouseDown event of tree view item for "Windows1" only?
You can inspect the ParentTreeView property of the treeview item that fired the event and to execute your handler code only if the treeview is in the appropriate UserControl.
Will this work for you?
Greetings,
Valentin.Stoychev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I'm also working with a right click selection problem. If I use your code(even the sample) when you right click an item I would like to have the focus (selection) select the new right clicked item and remove focus from the old left clicked item. How can I do that? Thanks
have you tried explicitly focusing the item, like so:
treeViewitem.IsSelected = true; |
treeViewitem.Focus(); |
I tried this with the code from the class event handler.
Does this work in your case?
Sincerely yours,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks
The mouse hover cannot be switched on / off since it is implemented as a Trigger for the IsMouseOver property of the visual element.
If you need another item to be appear highlighted then you can try selecting it, but this is not exactly the same as highlighting.
I am not sure I understood you fully, could you please clarify a bit why you need to turn on/off the highlight.
Kind regards,
Miroslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Hello,my friend.Now, I hava a big trouble when I use above code , this RadTreeview control selected many item when I right click many defferent item.you will clear when you look the attach files.Please give me reply as soon as possible. Thanks my friend.
UI code:
<
Telerik:RadTreeView
Name
=
"_treeView"
ScrollViewer.HorizontalScrollBarVisibility
=
"Hidden"
ScrollViewer.VerticalScrollBarVisibility
=
"Hidden"
SelectionMode
=
"Extended"
ExpanderStyle
=
"{StaticResource Expander}"
>
<
telerikNavigation:RadContextMenu.ContextMenu
>
<
telerikNavigation:RadContextMenu
x:Name
=
"radTreeViewMenu"
>
<
telerikNavigation:RadMenuItem
Header
=
"Add Division"
Tag
=
"Add Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Copy Division"
Tag
=
"Copy Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Rename Division"
Tag
=
"Rename Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Delete Division"
Tag
=
"Delete Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Compose Division"
Tag
=
"Compose Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Show PDF AT Division"
Tag
=
"Show PDF AT Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Show Clean PDF At Division"
Tag
=
"Show Clean PDF At Division"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Job Ticket"
Tag
=
"Job Ticket"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Add Job"
Tag
=
"Add Job"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Rename Job"
Tag
=
"Rename Job"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Delete Job"
Tag
=
"Delete Job"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Compose Job"
Tag
=
"Compose Job"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Show PDF"
Tag
=
"Show PDF"
IsEnabled
=
"False"
/>
<
telerikNavigation:RadMenuItem
Header
=
"Show Clean PDF At Job"
Tag
=
"Show Clean PDF At Job"
IsEnabled
=
"False"
/>
</
telerikNavigation:RadContextMenu
>
</
telerikNavigation:RadContextMenu.ContextMenu
>
</
Telerik:RadTreeView
>
This is because you have set the SelectionMode to Extended and you are probably setting the selection in code behind. However, if you want to have only one selected item on right click you have to deselect the previously right clicked item. I've attached a sample project demonstrating this functionality. Have a look at it and let me know if it helps.
All the best,
Kiril Stanoev
the Telerik team