2014-10-28 85 views
2

我嘗試創建應用程序使用用戶Control.I'm已經創建MainPage.xaml中這裏的代碼如下用戶控制8.1

<phone:PhoneApplicationPage 
x:Class="test.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
xmlns:local="clr-namespace:test" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
SupportedOrientations="Portrait" Orientation="Portrait" 
shell:SystemTray.IsVisible="True"> 

<!--LayoutRoot is the root grid where all page content is placed--> 

和用戶控制,其中我需要以下定義:

<UserControl x:Class="test.UserControls" 
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" 
mc:Ignorable="d" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" Height="50" Width="427"> 


<Canvas x:Name="SpatialCanvas" Background="Wheat"> 
    <Border 
     x:Name="dragSelectionBorder" 
     BorderBrush="Blue" 
     BorderThickness="1" 
     Background="LightBlue" 
     CornerRadius="1" 
     Opacity="0.5" 
     /> 
</Canvas> 

何w將此用戶控件稱爲MainPage.xaml

回答

1

您有xmlns:local="clr-namespace:test",這是對您的MainPage和您的自定義UserControl的命名空間的引用。

所以使用它MainPage執行

<local:USER_CONTROL_NAME/> 

在你的情況你的用戶控件被命名爲UserControls(你應該重新考慮更名是)

所以最後能夠使用自定義的控制

<local:UserControls/> 
+0

我使用 但它不顯示客戶控制 – diy 2014-10-28 11:15:31

+0

@diy應該工作,如果你像在問題中那樣定義你的'local'。我不知道你在用'Name',你沒有綁定,也沒有發佈任何代碼來顯示。 – 2014-10-28 11:19:27

+0

Thnx Chubosaurus軟件它工作正常 – diy 2014-10-28 11:28:27