I bind ItemsSource property to collection of elements that have 'IsChecked' property. How to bind 'RadTreeViewItem.IsChecked' property to 'MyElement.IsChecked'?
It is needed because I set IsVirtualizing="True" and thus I have to store whether item is checked in separate place.
It is needed because I set IsVirtualizing="True" and thus I have to store whether item is checked in separate place.
6 Answers, 1 is accepted
0
Hello Roman,
You can use the ItemContainerStyle property of the RadTreeView and set a style targeting RadTreeViewItem. You can examine this article showing how to bind the IsSelected property. Binding the IsChecked should be the same. Feel free to ask if you need further assistance.
Regards,
Petar Mladenov
the Telerik team
You can use the ItemContainerStyle property of the RadTreeView and set a style targeting RadTreeViewItem. You can examine this article showing how to bind the IsSelected property. Binding the IsChecked should be the same. Feel free to ask if you need further assistance.
Regards,
Petar Mladenov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Roman
Top achievements
Rank 1
answered on 27 Dec 2010, 03:10 PM
I wrote the following style:
But bindings seems to work only one way. Also when I set
Properties binding works only for visible elements, when I scroll down all new elements are unchecked.
Here is full XAML code:
And backing code:
<
t:RadTreeView.ItemContainerStyle
>
<
Style
TargetType
=
"t:RadTreeViewItem"
>
<
Setter
Property
=
"IsChecked"
Value
=
"{Binding Path=IsChecked, Mode=TwoWay}"
/>
</
Style
>
</
t:RadTreeView.ItemContainerStyle
>
But bindings seems to work only one way. Also when I set
IsVirtualizing="True" t:TreeViewPanel.VirtualizationMode="Recycling"
Here is full XAML code:
<
Window
x:Class
=
"WpfApplication4.MainWindow"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
DockPanel
>
<
StackPanel
Orientation
=
"Horizontal"
DockPanel.Dock
=
"Top"
>
<
Button
Content
=
"Check All"
Click
=
"CheckAll_Click"
Margin
=
"6"
Padding
=
"4, 0"
/>
<
Button
Content
=
"Uncheck All"
Click
=
"UncheckAll_Click"
Margin
=
"6"
Padding
=
"4, 0"
/>
<
Button
Content
=
"Count"
Click
=
"Count_Click"
Margin
=
"6"
Padding
=
"4, 0"
/>
<
TextBlock
Name
=
"label"
Text
=
"Count"
VerticalAlignment
=
"Center"
/>
</
StackPanel
>
<
t:RadTreeView
x:Name
=
"tree"
IsOptionElementsEnabled
=
"True"
ItemsOptionListType
=
"CheckList"
IsVirtualizing
=
"True"
t:TreeViewPanel.VirtualizationMode
=
"Recycling"
>
<!--t:RadTreeView x:Name="tree" IsOptionElementsEnabled="True" ItemsOptionListType="CheckList"-->
<
t:RadTreeView.ItemContainerStyle
>
<
Style
TargetType
=
"t:RadTreeViewItem"
>
<
Setter
Property
=
"IsChecked"
Value
=
"{Binding Path=IsChecked, Mode=TwoWay}"
/>
</
Style
>
</
t:RadTreeView.ItemContainerStyle
>
</
t:RadTreeView
>
</
DockPanel
>
</
Window
>
And backing code:
using
System;
using
System.Linq;
using
System.Windows;
using
System.Collections.ObjectModel;
using
System.ComponentModel;
namespace
WpfApplication4
{
public
partial
class
MainWindow : Window
{
ObservableCollection<MyItem> list =
new
ObservableCollection<MyItem>();
public
MainWindow()
{
InitializeComponent();
for
(
int
i = 0; i < 100; i++)
list.Add(
new
MyItem() { Text =
"item "
+ i, IsChecked =
false
});
tree.ItemsSource = list;
}
private
void
CheckAll_Click(
object
sender, RoutedEventArgs e)
{
foreach
(var item
in
list)
item.IsChecked =
true
;
}
private
void
UncheckAll_Click(
object
sender, RoutedEventArgs e)
{
foreach
(var item
in
list)
item.IsChecked =
false
;
}
private
void
Count_Click(
object
sender, RoutedEventArgs e)
{
label.Text = list.Where(a => a.IsChecked).Count().ToString();
}
}
public
class
MyItem : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
public
string
Text {
get
;
set
; }
private
bool
isChecked;
public
bool
IsChecked
{
get
{
return
isChecked; }
set
{
isChecked = value;
if
(PropertyChanged !=
null
) PropertyChanged(
this
,
new
PropertyChangedEventArgs(
"IsChecked"
));
}
}
public
override
string
ToString()
{
return
Text;
}
}
}
0
Hello Roman,
Unfortunately this appears to be a bug in the RadTreeView. The good new is that there is an elegant workaround using converter and CheckState property of the RadTreeViewItem. You can check out this blog post for more info and examine the attached solution accordingly.
You can also track the progress and vote the issue you`ve encountered here.
I also updated your telerik points.
Feel free to ask if you need further into.Thank you for your cooperation.
Best wishes,
Petar Mladenov
the Telerik team
Unfortunately this appears to be a bug in the RadTreeView. The good new is that there is an elegant workaround using converter and CheckState property of the RadTreeViewItem. You can check out this blog post for more info and examine the attached solution accordingly.
You can also track the progress and vote the issue you`ve encountered here.
I also updated your telerik points.
Feel free to ask if you need further into.Thank you for your cooperation.
Best wishes,
Petar Mladenov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Hello Roman,
We want to inform you, that this issue is already fixed.
You can check it in our latest internal build (released on 2 of May).
Any feedback/comments on the subject are highly appreciated.
Kind regards,
Vladislav
the Telerik team
We want to inform you, that this issue is already fixed.
You can check it in our latest internal build (released on 2 of May).
Any feedback/comments on the subject are highly appreciated.
Kind regards,
Vladislav
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Christian
Top achievements
Rank 1
answered on 16 Mar 2016, 01:10 PM
Hi @ll admins,
I am using Telerik for WPF (2016.1.112) and it seems the bug already exists.
Also: initially null is interpreted as false.
Best regards
Christian
0
Hi Christian,
There are known issues in the checkbox support for RadTreeView in a data binding scenario. This is why I recommend you to implement custom checkbox logic as demonstrated in the Implement a Tri-State CheckBox logic using MVVM help article. I hope this solution works for you.
Regards,
Martin
Telerik
There are known issues in the checkbox support for RadTreeView in a data binding scenario. This is why I recommend you to implement custom checkbox logic as demonstrated in the Implement a Tri-State CheckBox logic using MVVM help article. I hope this solution works for you.
Regards,
Martin
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.