This project has moved. For the latest updates, please go here.

Childwindow error on build

Sep 12, 2011 at 10:51 PM

Hi, i've been trying to use childwindow control (.Net 3.5) but i keep getting the following error:

Object reference not set to an instance of an object.

at Microsoft.Windows.Controls.ChildWindow.OnApplyTemplate()

at System.Windows.FrameworkElement.ApplyTemplate()

at Microsoft.Expression.Platform.WPF.WpfViewNodeManager.EnsureElementInDictionary(Object root, ViewNode knownAncestor)

I have referenced the right dll(.Net 3.5dll). Every time i build the project that error keeps coming. Here's the xaml code:

<UserControl x:Class="SPIN.ActionNet.AV61850Browser.dlgIEDs"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
        ><!--d:DesignHeight="320" d:DesignWidth="250"-->
    <extToolkit:ChildWindow x:Name="chdIEds" Caption="IEDs Configuration" IsModal="True" CloseButtonVisibility="Collapsed"  >
    <Grid>
        <Grid.RowDefinitions  >
            <RowDefinition Height="80" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Margin="2">
            <AccessText x:Name="lblWarning" TextWrapping="Wrap" Text="lblWarning" />
        </Label>
        <ListBox x:Name="lbIEDs" Grid.Row="1" Margin="2" ItemsSource="{Binding IEDDevicesList}" />
        <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
            <Button x:Name="cmdOk" Content="_Ok" IsDefault="True" Height="25" Width="70" Click="cmdOk_Click" />
            <Button x:Name="cmdCancel" Content="_Cancel" IsCancel="True" Height="25" Width="70" Click="cmdCancel_Click" />            
        </StackPanel>
    </Grid>
    </extToolkit:ChildWindow>
</UserControl>
What am i doing wrong?
What can i do to fix it?
Thanks, 
Leonardo

Sep 12, 2011 at 10:57 PM

Did you unblock the assembly as stated in the documentation?

http://wpftoolkit.codeplex.com/documentation

Sep 13, 2011 at 3:54 PM

Yes i did.

Just to make sure, i've removed the reference from the project, closed visual studio, deleted the dll, downloaded it again, unblocked the zip, added the reference to the project and added xmlns and using statement to my files.

The error persists.

Descrição: spinassinatura

Leonardo Klarmann Porto
Engenharia de Software
+55 61 9100-0645
Skype: nardoporto

SCLN 212 Bloco D Sala 101 - Asa Norte
Brasilia - DF 70864-540
+55 61 3340 8486
www.spinengenharia.com.br

Sep 14, 2011 at 7:45 AM

When I get some time I will check this out.  I do not fully test the .NET 3.5 controls and there might be something in the code causing this issue in 3.5.  I am at the BUILD conference and won't be able to get to it until next week.  Does it work at runtime?

Sep 14, 2011 at 2:25 PM

Well, i am trying to use it setting a dependency property and binding it to windowstate property. I couldn’t made it right though. The childwindow never appears when I set it to open.

I’m thinking about making another project, a sample one, so I can figure out what I’m doing wrong.

Leonardo Klarmann Porto
Engenharia de Software
+55 61 9100-0645
Skype: nardoporto

SCLN 212 Bloco D Sala 101 - Asa Norte
Brasilia - DF 70864-540
+55 61 3340 8486
www.spinengenharia.com.br

Sep 14, 2011 at 9:15 PM

Hi brianlagunas, i’m replying this just to say that the control is working fine at runtime.

I have figured out my mistakes.

But that error on the xaml still persists when building the project. Even when you add the control to an empty project and build it.

Thanks for the help.

Leonardo Klarmann Porto
Engenharia de Software
+55 61 9100-0645
Skype: nardoporto

SCLN 212 Bloco D Sala 101 - Asa Norte
Brasilia - DF 70864-540
+55 61 3340 8486
www.spinengenharia.com.br

Nov 9, 2011 at 11:38 AM

Hi,

   I am also getting the same above error. I am using .net 3.5 version of extended toolkit dll. I am getting

Object reference not set to an instance of an object.

at Microsoft.Windows.Controls.ChildWindow.OnApplyTemplate()

at System.Windows.FrameworkElement.ApplyTemplate()

Can you help on this???

Nov 9, 2011 at 2:23 PM

I am sure it has something to do wih the the code in the OnApplyTemplate method of the ChildWindow.cs.  For some reason it behaves differently in .NET 3.5 than in 4.0.  I don't know if I will spend anytime on this one, becase I don't think I will support .NET 3.5 much longer.

Jun 27, 2012 at 1:35 PM

Not sure if this helps anyone but I get this on the .net 4.0 version when the ChildWindow does not have a grid or Window as the parent control (as in the leokporto's example). This is because the _parentContainer and WindowRoot end up null when OnApplyTemplate is called. As a workaround I have just put a not null check around any code relating to these and everything works fine now.