Binding RadPane IsHidden to ViewModel property set to True causes NullReferencedException

9 posts, 1 answers
  1. Joe Biggert
    Joe Biggert avatar
    17 posts
    Member since:
    Feb 2010

    Posted 27 Feb 2012 Link to this post

    When I have my RadPane's IsHidden property bound to a boolean ViewModel property which is set to true, I get an exception from within Telerik's RadDocking code:

    System.NullReferenceException was unhandled by user code
      Message=Object reference not set to an instance of an object.
      Source=Telerik.Windows.Controls.Docking
      StackTrace:
           at Telerik.Windows.Controls.RadDocking.OnRadPaneClose(Object sender, StateChangeCommandEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Docking\Docking\Docking\RadDocking.cs:line 834
      InnerException: 

    Right now this is preventing me from implementing a full MVVM using your controls. I'm hoping this is something I've done wrong but if not, is there any workaround that I can use to get me past this before this bug is fixed (it is a bug)?

    From my sample project with only this in it:

    Here's my View XAML:

    <Window x:Class="Telerik_IsHidden_RadPane_Bug.MainView"
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"        mc:Ignorable="d"
            DataContext="{Binding Main, Source={StaticResource Locator}}">
     
        <Grid>
            <!--  Main Window Docking Container (stretch to fill grid) -->
            <telerik:RadDocking Grid.Row="1"
                                HasDocumentHost="false"
                                HorizontalAlignment="Stretch"
                                Margin="0,0,0,32"
                                Name="radDockingMainWindow"
                                VerticalAlignment="Stretch" >
     
                <!--  Split container that holds all of the accordion panels -->
                <telerik:RadSplitContainer telerik:DockingPanel.InitialSize="300, 200"
                                           Name="AccordionContainer"
                                           InitialPosition="DockedLeft"
                                           Orientation="Vertical" VerticalAlignment="Stretch" >
                    <!--  Panes must be in pane groups, even if there is just 1 -->
                    <telerik:RadPaneGroup MaxWidth="300" x:Name="ToolWindow1Group" >
                        <telerik:RadPane x:Name="ToolWindow1" Title="" CanUserClose="False" CanUserPin="False" CanFloat="True">
                            <Button Content="Example" />
                        </telerik:RadPane>
                    </telerik:RadPaneGroup>
                </telerik:RadSplitContainer>
                <telerik:RadSplitContainer InitialPosition="FloatingDockable"                                 
                        telerik:RadDocking.FloatingLocation="450, 250"
                        telerik:RadDocking.FloatingSize="300, 220" x:Name="uxWindowRadSplitContainer" >
                    <telerik:RadPaneGroup>
                        <telerik:RadPane Header="Intellifolders" CanDockInDocumentHost="False" IsHidden="{Binding Path=ToolWindowProp}" x:Name="uxToolWindowRadPane">
                            <TextBlock Text="Hi" />
                        </telerik:RadPane>
                    </telerik:RadPaneGroup>
                </telerik:RadSplitContainer>
            </telerik:RadDocking>
     
        </Grid>
    </Window>


    And here's my ViewModel code:

    using GalaSoft.MvvmLight;
     
    namespace Telerik_IsHidden_RadPane_Bug
    {
        /// <summary>
        /// This class contains properties that a View can data bind to.
        /// <para>
        /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
        /// </para>
        /// <para>
        /// </para>
        /// </summary>
        public class MainViewModel : ViewModelBase
        {
            public bool ToolWindowProp  
    {
    get; set; }
     
            /// <summary>
            /// Initializes a new instance of the MainViewModel class.
            /// </summary>
            public MainViewModel()
            {
                ToolWindowProp = true;
            }
        }
    }


  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 05 Mar 2012 Link to this post

    Hello Joe,

    Please find attached a sample project in which is illustrated the recommended approach for binding the IsHidden property to a ViewModel. I am not sure about the exception, please give the sample a try and let us know if you still experience the problem, along with details about the version of the controls you are using and any other code associated with the Docking control. Usually the issue associated with binding the IsHidden property is that the DataContext is lost when the pane is in floating mode.
    The project is for Silverlight, however, the logic is the same for WPF also.

    Hope this helps.

    Kind regards,
    Konstantina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Joe Biggert
    Joe Biggert avatar
    17 posts
    Member since:
    Feb 2010

    Posted 05 Mar 2012 Link to this post

    When use the code in the sample files you sent in a WPF application, I get the NullReferenceException I mentioned in my original post.
  5. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 06 Mar 2012 Link to this post

    Hi,

    Did you modify the project? Could you please send it to us in order to debug it and track down the source of the problem? Also, could you please share with us with which version of the controls you are experiencing this issue?

    All the best,
    Konstantina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Joe Biggert
    Joe Biggert avatar
    17 posts
    Member since:
    Feb 2010

    Posted 07 Mar 2012 Link to this post

    Because the project you sent was Silverlight, I had to rebuild it in WPF; I wasn't able to simply convert it in place. I am using version 2011.3.1220.40 of your controls.

    Here's a download link to the project: http://www.cwithb.com/Telerik IsHidden RadPane Bug.zip
  7. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 12 Mar 2012 Link to this post

    Hi Joe,

    We confirm this is a bug in the Docking control. We will do our best to provide a fix for the service pack. However, our tasks are already planned, so if we not manage to fix it for the service pack, we will provide a fix shortly after that. Here is the PITS item which you can track.
    Sorry for the caused inconvenience.
    If you are still using the 2011.3.1220.40 version I can suggest you a work-around: create the ViewModel instance in code-behind and assign the according properties after the InitializeComponent() execution. In the version that you are using this will work-around the problem and avoid the exception.

    Regards,
    Konstantina
    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. Joe Biggert
    Joe Biggert avatar
    17 posts
    Member since:
    Feb 2010

    Posted 30 Jul 2012 Link to this post

    While the item is still in progress on PITS, I noticed the 2012 Q2 SP1 release notes mention this herE:

    NullReferenceException is being thrown when a ViewModel is assigned to the Docking control and IsHidden property is bound 


    So I tried this out and lo and behold, the NullReferenceException no longer gets thrown just like the release notes says... the fun part is that while y'all made a change that prevents the exception from getting thrown, the binding still doesn't work. If I load with the IsHidden property bound to a VM property who's initial value is True, the RadPane still shows up when the application loads (although its content is not visible which is really odd). Should this be a separate ticket?
  9. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 02 Aug 2012 Link to this post

    Hi Joe,

    Thank you for your feedback.

    I have just tested this and it seems that when the IsHidden property is set to true the RadPane is removed from the VisualTree, so it loses its DataContext and the IsHidden binding is not working anymore. We will need additional time to investigate this. I will write you back once we have more information.

    Regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Joe Biggert
    Joe Biggert avatar
    17 posts
    Member since:
    Feb 2010

    Posted 06 Aug 2012 Link to this post

    Thank you for the update Ivo.
Back to Top
UI for WPF is Visual Studio 2017 Ready