如何在不同的文件夹中使用本地/用户控制

Tai*_*yen 5 c# wpf xaml

我有一个问题。

我不想复制我的代码,所以我看到我可以使用:用户控制/本地问题是当我使用本地时,我只能调用与该文件夹位于同一文件夹中的文件,我想调用我的文件在另一个文件夹中。

例子 :

在我的布局/_Menu.xaml

<UserControl
    x:Class="TeysserWP8.Views.misc._menuLayout"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TeysserWP8.Views.misc"
    xmlns:drawerLayout="using:DrawerLayout"
    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>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FF563AA0" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
        <Button Command="{Binding MyDietViewCommand}" Content="Mes Régimes" Margin="10,21,0,502" Width="245"></Button>
        <Button Command="{Binding DietStoreViewCommand}" Content="Régimes Store" Margin="10,89,0,434" Width="245"></Button>
        <Button Command="{Binding LogoutViewCommand}" Content="Déconnexion" Margin="10,502,0,21" Width="245"></Button>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

在我的商店/Show.xaml

<Grid>
  some code
</Grid>
<local:/Layout/_Menu />  <-- i Want something like this but its not work.
Run Code Online (Sandbox Code Playgroud)

如果 _Menu.xaml 文件与 Show.xaml ( Store Folder ) 位于同一文件夹中,则它会起作用。

你能帮助我吗 ?谢谢。

Ath*_*oud 5

我不认为这与文件夹有关。在 XAML 中,在引用当前类所在的命名空间时,大多数情况下使用本地别名。这不是强制性的。

检查您要引用的类

<local:/Layout/_Menu /> 
Run Code Online (Sandbox Code Playgroud)

位于您在 XAML 文件顶部声明的命名空间中。对于您的情况,请检查TeysserWP8.Views.misc命名空间

xmlns:local="using:TeysserWP8.Views.misc"
Run Code Online (Sandbox Code Playgroud)