Why are all objects in this extension of usercontrol null at runtime?

Posted by csciguy on Stack Overflow See other posts from Stack Overflow or by csciguy
Published on 2010-03-29T20:23:27Z Indexed on 2010/04/04 2:43 UTC
Read the original article Hit count: 378

Filed under:
|
|
|

All,

I have a simple class.

public class Container : UserControl
{
    public bool IsClickable { get; set; }
}

I have a class that extends this class.

public class ScrollingContainer : Container
{
    public void Draw()
    {

    }

    public void Update()
    {

    }
}

I have a custom class, that then extends ScrollingContainer.

public partial class MaskContainer : ScrollingContainer
{

    public MaskContainer()
    {
        InitializeComponent();
    }
}

XAML

<local:ScrollingContainer x:Class="Test.Types.MaskContainer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:GameObjects;assembly=GameObjects"
    mc:Ignorable="d"
    >
</local:ScrollingContainer>

In my mainpage.xaml, I have the following.

<types:MaskContainer x:Name="maskContainer" Canvas.ZIndex="1" Width="Auto" Height="Auto">
       <Canvas x:Name="maskCanvas">
           <Button x:Name="button1" Content="test button"/>
       </Canvas>
</types:MaskContainer>

Why, at runtime, are both maskCanvas and button1 null? maskContainer is not null.

The inheritance should be straightforward here. Container inherits usercontrol. Scrollable container inherits container. Mask Container inherits scrollable container. Why am I losing the fucntionality of the original base class at this level? Is it incorrect to add the element (button1) to the maskcontainer inside of the main.xaml?

My end goal is to create a container that is reusable, but inherits all properties/methods that I've specified throughout the chain.

Any help is appreciated.

© Stack Overflow or respective owner

Related posts about silverlight-4.0

Related posts about .NET