如何在XAML中使用来自dll/程序集的控件?

如何在XAML中使用来自dll/程序集的控件?,xaml,windows-8,visual-studio-2012,windows-runtime,c++-cx,Xaml,Windows 8,Visual Studio 2012,Windows Runtime,C++ Cx,我在dll中有一个CustomControl派生类(MyNamespace.UI)。如何在主应用程序中使用此控件?我尝试添加对项目的引用,然后使用自定义XAML命名空间指向我的命名空间,但它找不到: <Page ... xmlns:ui="using:MyNamespace.UI" ...> <Canvas> <ui:MyControl /> </Canvas> </Page> edit2我删除了Grid控件,

我在dll中有一个
CustomControl
派生类(
MyNamespace.UI
)。如何在主应用程序中使用此控件?我尝试添加对项目的引用,然后使用自定义XAML命名空间指向我的命名空间,但它找不到:

<Page ...
    xmlns:ui="using:MyNamespace.UI"
    ...>
<Canvas>
    <ui:MyControl />
</Canvas>
</Page>

edit2我删除了
Grid
控件,构建并运行了它,然后我将
Grid
控件放回原处,它仍然工作。非常奇怪。

您需要确保
MyNamespace.UI
程序集具有与
MyNamespace.UI
匹配的
RootNamespace
属性。无法在“项目设置”页面中更改此属性,但可以通过记事本或等效工具进行更改。我的
RootNamespace
设置为
UI
,当我更改它时,它开始工作

<UserControl
    x:Class="MyNamespace.UI.MyControl"
    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"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid>

    </Grid>
</UserControl>