2014-10-28 82 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