This is a migrated thread and some comments may be shown as answers.

Show treeview checkbox but disable it

7 Answers 196 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Karl
Top achievements
Rank 1
Karl asked on 13 Jan 2011, 06:20 PM
I currently have a Treeview component with checkboxes.  How can I continue to display the checkboxes but also enable/disable the ability to edit the state based on a binding property?

Thanks,
Karl

7 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 18 Jan 2011, 01:49 PM
Hi Karl,

You can edit the default ControlTemplate of the RadTreeViewItem in ExpressionBlend following the approach described here. Then you can bind the IsEnabled property of the CheckBoxElement accordingly:
<!--TreeViewItemDefaultTemplate-->
<ControlTemplate x:Key="TreeViewItemDefaultTemplate"
    TargetType="telerik:RadTreeViewItem">
    <Grid x:Name="RootElement">
    ...
 
        <!--CheckBoxElement-->
        <CheckBox x:Name="CheckBoxElement"
                Grid.Column="2"
                IsTabStop="False"
                Margin="5,0,0,0"
                telerik:StyleManager.Theme="{StaticResource Theme}"
                Visibility="Collapsed"
                VerticalAlignment="Center"
                IsEnabled="{Binding CheckEnabled}" />
    ...
</ControlTemplate>

I prepared a sample project illustrating this suggestion. Give it a try and let us know if it works for you or if you need more info.

Best wishes,
Tina Stancheva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Karl
Top achievements
Rank 1
answered on 18 Jan 2011, 03:21 PM
Hi Tina,

Thank you for the demo, it works as I expected.

Karl
0
Manoj
Top achievements
Rank 1
answered on 07 Mar 2012, 04:40 PM
I am using this approach. It is working But i need to bind IsChecked property too. I have tried as follows but not working.
<!--CheckBoxElement--> 
               <CheckBox x:Name="CheckBoxElement"
                             Grid.Column="2"
                             IsTabStop="False"
                             Margin="5,0,0,0"
                             telerikrad:StyleManager.Theme="{StaticResource Theme}"
                             Visibility="Collapsed"
                             VerticalAlignment="Center"
                             IsEnabled="{Binding CheckEnabled}" IsChecked="{Binding IsCheckChecked}" />
Please suggest. Its urgent for me.
0
Manoj
Top achievements
Rank 1
answered on 09 Mar 2012, 07:15 PM
Hi Telerik Team,

I am waiting from 2 days for answer. Please reply its urgent.
0
Petar Mladenov
Telerik team
answered on 12 Mar 2012, 08:59 AM
Hi Manoj,

In this case you cannot use the CheckBox to bind its IsChecked property properly, because the Style setting the CheckState has bigger priority.

<Setter Property="CheckState" Value="Off" />
So you have to bind the CheckState instead , like so:
<Setter Property="CheckState" Value="{Binding IsCheckChecked, Converter={StaticResource converter}}" />
You can find this realized in the attached solution. However, if you need to use TriState behavior and bind the CheckState too, you have to implement the TriState logic in the ViewModels since there is known related issue in the RadTreeView.
We strongly suggest you to submit a support ticket if you need to take advantage of our priority  (24) support. Thank you for your understanding. 

Kind regards,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Manoj
Top achievements
Rank 1
answered on 12 Mar 2012, 06:28 PM
I am getting following error (In Attachment) in this solution. I am using red silverlight controls - v.2011.3.1116.1040 Dev.
0
Tina Stancheva
Telerik team
answered on 14 Mar 2012, 01:53 PM
Hi Manoj,

Please accept our apology for this misunderstanding. In Silverlight 4 the proper implementation of your scenario is to use ContainerBindings instead of a Style Setter to bind the CheckState property of the RadTreeViewItems:
<telerik:ContainerBindingCollection x:Key="TreeViewBindingsCollection">
    <telerik:ContainerBinding Binding="{Binding IsCheckChecked, Converter={StaticResource converter}, Mode=TwoWay}"
                              PropertyName="CheckState" />
</telerik:ContainerBindingCollection>
 
<!--  TreeItemDataTemplate  -->
<telerik:HierarchicalDataTemplate x:Key="TreeItemDataTemplate"
                                  ItemsSource="{Binding Children}"
                                  telerik:ContainerBinding.ContainerBindings="{StaticResource TreeViewBindingsCollection}">
    <StackPanel>
        <TextBlock Text="{Binding Header}" />
    </StackPanel>
</telerik:HierarchicalDataTemplate>

I updated the solution accordingly. Give it a try on your side and let us know if it works.

Regards,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
TreeView
Asked by
Karl
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Karl
Top achievements
Rank 1
Manoj
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or