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

Binding RadPane IsHidden to ViewModel property set to True causes NullReferencedException

11 Answers 277 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Joe Biggert
Top achievements
Rank 1
Joe Biggert asked on 27 Feb 2012, 11:58 PM
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;
        }
    }
}


11 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 05 Mar 2012, 10:29 AM
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 >>
0
Joe Biggert
Top achievements
Rank 1
answered on 05 Mar 2012, 09:41 PM
When use the code in the sample files you sent in a WPF application, I get the NullReferenceException I mentioned in my original post.
0
Konstantina
Telerik team
answered on 06 Mar 2012, 04:21 PM
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 >>
0
Joe Biggert
Top achievements
Rank 1
answered on 07 Mar 2012, 06:55 PM
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
0
Accepted
Konstantina
Telerik team
answered on 12 Mar 2012, 01:42 PM
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 >>
0
Joe Biggert
Top achievements
Rank 1
answered on 30 Jul 2012, 02:21 PM
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?
0
Ivo
Telerik team
answered on 02 Aug 2012, 03:30 PM
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.

0
Joe Biggert
Top achievements
Rank 1
answered on 06 Aug 2012, 07:42 PM
Thank you for the update Ivo.
0
Dharmavaram
Top achievements
Rank 1
answered on 26 Sep 2017, 08:33 AM

Hi

Iam getting Nullreference exception, but when i first set Radpane hidden to true it is perfectly hiding the radpane then, i am setting hidden property to false it is not working, i am not able to see radpane. I have even tried to set DataContext
On the RadPane still it has same promblem

Below is the code

 <telerik:RadPane IsHidden="{Binding PaneHidden}" DataContext="{Binding ElementName=RadDocking,Path=DataContext}" Name="testViewPane" Header="Test View" CanUserClose="False" IsPinned="True"  IsSelected="{Binding IsTestViewTreeActive}" >

</telerik:RadPane>

Is there any other property that helps me in hiding and unhiding the radpane. or any other way i can achieve using ishidden property.

-Nagasree

0
Dharmavaram
Top achievements
Rank 1
answered on 26 Sep 2017, 08:36 AM

Edited the above question

Iam not getting Nullreference exception, but when i first set Radpane hidden to true it is perfectly hiding the radpane then, i am setting hidden property to false it is not working, i am not able to see radpane. I have even tried to set DataContext
On the RadPane still it has same promblem
Below is the code
 <telerik:RadPane IsHidden="{Binding PaneHidden}" DataContext="{Binding ElementName=RadDocking,Path=DataContext}" Name="testViewPane" Header="Test View" CanUserClose="False" IsPinned="True"  IsSelected="{Binding IsTestViewTreeActive}" >
</telerik:RadPane>
Is there any other property that helps me in hiding and unhiding the radpane. or any other way i can achieve using ishidden property. 

0
Stefan
Telerik team
answered on 29 Sep 2017, 07:55 AM
Hello Dharmavaram,

Thanks for the provided code.

As already discussed in this thread, when a given RadPane is hidden, it is removed from the VisualTree. In such case its DataContext is lost as well. May I kindly ask you to try setting the DataContext of the RadPane to be a StaticResource instead of binding it? Is the property working as expected with such setup?

Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Docking
Asked by
Joe Biggert
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Joe Biggert
Top achievements
Rank 1
Ivo
Telerik team
Dharmavaram
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or