Show treeview checkbox but disable it

8 posts, 0 answers
  1. Karl
    Karl avatar
    12 posts
    Member since:
    Jan 2011

    Posted 13 Jan 2011 Link to this post

    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
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 18 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Karl
    Karl avatar
    12 posts
    Member since:
    Jan 2011

    Posted 18 Jan 2011 Link to this post

    Hi Tina,

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

    Karl
  5. Manoj
    Manoj avatar
    43 posts
    Member since:
    Aug 2011

    Posted 07 Mar 2012 Link to this post

    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.
  6. Manoj
    Manoj avatar
    43 posts
    Member since:
    Aug 2011

    Posted 09 Mar 2012 Link to this post

    Hi Telerik Team,

    I am waiting from 2 days for answer. Please reply its urgent.
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 12 Mar 2012 Link to this post

    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 >>
  8. Manoj
    Manoj avatar
    43 posts
    Member since:
    Aug 2011

    Posted 12 Mar 2012 Link to this post

    I am getting following error (In Attachment) in this solution. I am using red silverlight controls - v.2011.3.1116.1040 Dev.
  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 14 Mar 2012 Link to this post

    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 >>
Back to Top
DevCraft banner