We have enabled radio buttons...
IsOptionElementsEnabled="True"
ItemsOptionListType="OptionList"
6 Answers, 1 is accepted
Yes, the Radio TreeViewItems are grouped per their parent node. But I believe there is a simple and elegant solution for your scenario here - you can use the PreviewChecked event of the RadTreeView and mark all previously checked items unchecked:
private
void
tree_PreviewChecked(
object
sender, RadRoutedEventArgs e)
{
IList checkedItems =
this
.tree.CheckedItems.ToList();
foreach
(var item
in
checkedItems)
{
(item
as
RadTreeViewItem).CheckState = ToggleState.Off;
}
}
You can find this approach realized in the attached sample. Regards,
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Is there a way to select the radio button by clicking on the treeitem (as opposed to the small click area of the radio button itself?) I am trying to give a better user experience of a large click area, and lessen the confusion between Option selected and item selected. (see attached)
You can use the PreviewSelectionChanged event like so:
private
void
tree_PreviewSelectionChanged(
object
sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
if
(e.AddedItems.Count != 0)
{
(e.AddedItems[0]
as
RadTreeViewItem).CheckState = ToggleState.On;
}
}
private
void
tree_PreviewSelectionChanged(
object
sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
if
(e.AddedItems.Count != 0)
{
(e.AddedItems[0]
as
RadTreeViewItem).CheckState = ToggleState.On;
}
e.Handled =
true
;
}
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
We have a problem when implimenting this using MVVM. We tried using this template
<
telerik:RadTreeView.ItemTemplate
>
<
telerik:HierarchicalDataTemplate
ItemsSource
=
"{Binding Children, Mode=TwoWay}"
>
<
telerik:RadTreeViewItem
Header
=
"{Binding Name}"
IsChecked
=
"{Binding IsChecked, Mode=TwoWay}"
IsEnabled
=
"{Binding IsEnabled, Mode=TwoWay}"
Width
=
"{Binding Path=ActualWidth, ElementName=treeWidth}"
/>
</
telerik:HierarchicalDataTemplate
> </
telerik:RadTreeView.ItemTemplate
>
if (e.AddedItems.Count != 0)
{
(e.AddedItems[0] as RadTreeViewItem).CheckState = ToggleState.On;
}
However in our model e.AddedItems[0] is a type of object of binded hierarchy (not a RadTreeViewItem). Therefore it cannot be cast to a RadTreeViewItem.
Any ideas?
I would like to advise you to use custom RadioButton in the TreeViewItem data template and bind their Checked state to you view model. I see you are employing MVVM and data binding. The benefit of this approach would be better programmatical control over the RadioButton states via the view model.
However there is a slight overhead of adding a property indicating the check state. Which you would have for free if using a binding to IsSelected.
Binding the IsSelected in your view model to IsSelected of the TreeViewItem and binding IsSelected from the view model to the RadioButton IsChecked will handle the case where you have a single checked item and the hit area is the whole item.
Finally, I'm sending a sample project to demonstrate you the approach.
Hope this helps. Let me know if the approach does not work for your case or you need more info.
Hristo
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>