XAML namespace identifier for UWP control

I'm building an extension SDK to install a Windows 10 UWP custom control in Visual Studio toolbox.
The extension SDK is installed ok, the custom control appears in the toolbox.
When I drag the custom control from the toolbox onto the XAML page, the control is added and the following entries appear in the page XAML:
- the attribute xmlns:View="using:Xfinium.Pdf.View" on the Page tag and
- the <View:PdfCoreView ... /> tag for the control.

My question is how do I customize my control so that the Visual Studio designer generates a different namespace for the control, such as 'xfs' ( xmlns:xfs="using:Xfinium.Pdf.View" ) instead of 'View'?


My question is how do I customize my control so that the Visual Studio designer generates a different namespace for the control

You could just manually define the value yourself with the xmlns as the prefix. You can manual add xmlns:xfs="using:Xfinium.Pdf.View to the declare of the Page to map the xfs to the custom using:Xfinium.Pdf.View namespace. And then when you drag the custom control from toolbox, it will have the xfs prefix as you want.

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    ...         
    x:Class="Cleantest.MainPage"
    mc:Ignorable="d"
    xmlns:xfs="using:Microsoft.Toolkit.Uwp.UI.Controls" 
     >
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
        <xfs:Carousel HorizontalAlignment="Left" Margin="161,254,0,0" VerticalAlignment="Top"/>
        <xfs:ImageEx HorizontalAlignment="Left" Margin="161,354,0,0" VerticalAlignment="Top"/>
        <!--<Controls:Carousel HorizontalAlignment="Left" Margin="161,254,0,0" VerticalAlignment="Top"/>-->
    </Grid>
</Page>

If you don't set the custom value for reference the namespace, directly drag a custom control from the toolbox, the prefix is auto generated with the namespace name. For example, Xfinium.Pdf.View should be View: , Microsoft.Toolkit.Uwp.UI.Controls should be Controls: . So that if you want to change this value you should change the namespace name of the original package.

Defined the value yourself in the page declaration is the recommended. Without this XAML will not have a different prefix with the namespace but the namespace own name.

链接地址: http://www.djcxy.com/p/61322.html

上一篇: 在主流浏览器中键入我的本地应用程序?

下一篇: 用于UWP控制的XAML名称空间标识符