2012-10-09 44 views
1

我試圖寫我自己的自定義TextBox控件在Silverlight 5的Silverlight 5.0自定義文本框:標籤「文本框」不命名空間

我已經有成功寫了一個自定義標籤控制,存在我可以在我的項目中重用。

XAML和標籤控制背後的代碼如下所示。

下面的代碼確實工作我:

<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(); 

     } 


    } 
} 

現在我想要做一個TextBox一樣 - 寫我自己的自定義TextBox控件。 對TextBox的代碼看起來是這樣的:正如你可以看到,它幾乎是同樣的事情

<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(); 

     } 



    } 
} 

而編造着解決出現以下錯誤:

「標籤‘文本框’在XML命名空間中不存在「http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'」

由於文本框控件似乎存在於System.Windows.Controls.TextBox命名空間中,我在XAML中嘗試了不同的命名空間,但沒有任何工作。

我的問題是:

哪個命名空間做我必須使用,要建立這個自定義文本?

如果它不是名稱空間問題,我錯過了什麼?

謝謝。

回答

1

這不是sdk:TextBox,只是TextBox(即http://schemas.microsoft.com/winfx/2006/xaml/presentation,這是大多數XAML文件中的默認xmlns)。儘管Silverlight TextBox課程中沒有記錄,但在.NET 4.5 TextBox課程中有記錄。

+0

謝謝。我可以在那裏看到。男人,小問題 - 2小時後。 – Michael