如何在xmal中嵌入来自另一个文件夹的xaml

zpgglvta  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(143)

project hierarchy
你好。我有主XAML UWP视图(MainTabbar.xaml)和选项卡内容视图(MethodTabView.xaml)。MethodTabView.xaml位于另一个文件夹中。我需要将MethodTabView.xaml嵌入MainTabbar.xaml中。如果两个文件在同一个文件夹中,一切都可以嵌入,但如果文件位于不同的文件夹中,它就不工作了。请帮助

hyrbngr7

hyrbngr71#

If I understand you correctly, you want to use the xaml control that you've created in another folder, right?
You will need to add references to the Page. I think you might change a little bit for your code.
I've made a simple demo and you could refer to it. I created a new Folder called MethodFolder , then I created a new UserControl called TestUserControl . After that, I added the reference to the page where I want to use the user control. Like:

xmlns:Name="using:ProjectName.FolderName"

So here is the code that I'm using:

<Page
x:Class="TestReference.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestReference"
xmlns:MethodFolder="using:TestReference.MethodFolder"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
    <MethodFolder:TestUserControl />
</Grid>

And this is the screenshot of my project:

相关问题