1
votes

I am trying to write my own custom TextBox control in Silverlight 5.

I already have successfully written a custom label control, which I can reuse in my project.

The XAML and the code behind for the label control look like this.

The following code does work for me:

<sdk:Label 

x:Class="Gui.CustomControls.LabelControl"
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:sw="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="125">

<Grid x:Name="LayoutRoot" Background="White">

</Grid>

using System;
using System.Collections.Generic;
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;

namespace Gui.CustomControls
{
    public partial class LabelControl : System.Windows.Controls.Label
    {
        public LabelControl()
        {
            InitializeComponent();

        }


    }
}

Now I want to do the same for a TextBox - writing my own custom TextBox Control. The code for the TextBox looks like this: As you may see, it is nearly the same thing

<sdk:TextBox 

    x:Class="Gui.CustomControls.TextBoxControl"
    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:sw="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    mc:Ignorable="d"
    d:DesignHeight="25" d:DesignWidth="125">

    <Grid x:Name="LayoutRoot" Background="White">

    </Grid>
</sdk:TextBox>

using System;
using System.Collections.Generic;
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;

namespace Gui.CustomControls
{
    public partial class TextBoxControl : System.Windows.Controls.TextBox
    {
        public TextBoxControl()
        {
            InitializeComponent();

        }



    }
}

While buliding the solution the following error occurs:

"The tag 'TextBox' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'"

As the textbox control seems to live in the System.Windows.Controls.TextBox Namespace, I tried different namespaces in the XAML, but nothing worked.

My question is:

Which namespace do I have to use, to build this custom textbox?

If it's not a namespace problem, what am I missing?

Thank you.

1

1 Answers

1
votes

It's not sdk:TextBox, just TextBox (i.e. http://schemas.microsoft.com/winfx/2006/xaml/presentation, which is the default xmlns in most XAML files). While oddly not documented on the Silverlight TextBox class, this is documented on the .NET 4.5 TextBox class.