RadTreeView with ControlTemplate causes crash when MouseWheel

3 posts, 1 answers
  1. Haz Parakrama
    Haz Parakrama avatar
    2 posts
    Member since:
    Sep 2009

    Posted 04 Sep 2009 Link to this post

    Hey Telerik,

    So I'm trying to create a simple ControlTemplate for the RadTreeView so I can combine the RadTreeView's hierarchy checkbox functionality (with IsTriStateMode and IsOptionElementsEnabled) with a custom ItemTemplate for each item bound to the tree.  Basically I want a RadTreeView with a root node that has a checkbox and the text "ALL", and give that node children of RadTreeViewItems.  My goal is to make it a single control, so fellow developers can just attach the style and desired ItemTemplate and roll with it (the idea is so this control could be used if the backing object needs to have its state changed when its corresponding node is checked or unchecked [obviously this needs subscribing to the event handlers as well, but that's irrelevant here]).

    The items get bound just fine and the checkboxes work and all as expected, but mousewheel-scrolling past the boundaries (at the top of the tree or at the bottom) throws an exception on the page:

    "System.NullReferenceException: Object reference not set to an instance of an object
    at Telerik.Windows.Controls.RadTreeView.OnRootVisualMouseWheel
    (Oject sender, MouseWheelEventArgs e)"

    My XAML is as follows:

    <UserControl x:Class="Haz.Silverlight.TestProject.Page" 
      Width="400" Height="300"
        <telerik:HierarchicalDataTemplate x:Key="TreeView"
          <TextBlock Text="{Binding Text, Mode=OneWay}"/> 
        <Style x:Name="RadTreeViewStyle" TargetType="rad:RadTreeView"
          <Setter Property="Template"
              <ControlTemplate TargetType="rad:RadTreeView"
                  MinHeight="{TemplateBinding MinHeight}" 
                  MinWidth="{TemplateBinding MinWidth}" 
                  Width="{TemplateBinding Width}" 
                  VerticalAlignment="{TemplateBinding VerticalAlignment}" 
                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
                  IsTriStateMode="{TemplateBinding IsTriStateMode}" 
                  IsOptionElementsEnabled="{TemplateBinding IsOptionElementsEnabled}"
                  <rad:RadTreeViewItem Header="ALL" CheckState="On" IsExpanded="True" ItemsSource="{TemplateBinding ItemsSource}" ItemTemplate="{TemplateBinding ItemTemplate}" /> 
                </rad:RadTreeView > 
      <Grid x:Name="LayoutRoot" Background="White"
        <rad:RadTreeView x:Name="tree" Style="{StaticResource RadTreeViewStyle}" ItemTemplate="{StaticResource TreeView}" Height="100" IsTriStateMode="True" IsOptionElementsEnabled="True" /> 

    And my code-behind:
    using System; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Collections.ObjectModel; 
    using System.Linq; 
    using System.Net; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Documents; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Animation; 
    using System.Windows.Shapes; 
    using System.Windows.Data; 
    namespace Haz.Silverlight.TestProject 
        public partial class Page : UserControl 
            private List<Data> list = new List<Data>(); 
            public Page() 
            public void Populate() 
                for (int i = 0; i < 10; i++) 
                    list.Add(new Data("ITEM " + i.ToString())); 
                this.tree.ItemsSource = list; 
        public class Data 
            private string _text; 
            public string Text 
                get { return _text; } 
                set { _text = value; } 
            public Data(string text) 
                Text = text; 

    I know I must be missing something, because if I DON'T set the ControlTemplate and structure my XAML as follows:

      <Grid x:Name="LayoutRoot" Background="White"
        <rad:RadTreeView Height="100" IsTriStateMode="True" IsOptionElementsEnabled="True"
          <rad:RadTreeViewItem  x:Name="tree" Header="ALL" CheckState="On" IsExpanded="True" ItemTemplate="{StaticResource TreeView}"/> 

    everything works fine.  Am I missing a property or something?

    This isn't urgent so deal with more pressing posts if you have them.  I'd appreciate any help though.


  2. Answer
    Valentin.Stoychev avatar
    2198 posts

    Posted 07 Sep 2009 Link to this post

    Hello Haz Parakrama,

    you will need to define a scrollviewer inside the control template of the RadTreeView and name it "ScrollViewer".

    This should fix the issue you are experiencing.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Haz Parakrama
    Haz Parakrama avatar
    2 posts
    Member since:
    Sep 2009

    Posted 08 Sep 2009 Link to this post


    Perfect!  Thanks very much.

Back to Top