您可以随时使用旧的用户控件。在这里,我为你提供了一个例子:
<UserControl
x:Class="App1.ReusableCode"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
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 VerticalAlignment="Center" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Text="SomeText" />
<TextBlock Text="Some Text 2" />
</StackPanel>
<StackPanel Name="stackPanel2" Grid.Row="1">
<TextBlock Text="SomeText 3" />
<TextBlock Text="Some Text 4" />
</StackPanel>
<StackPanel Name="stackPanel3" Grid.Row="2">
<TextBlock Text="SomeText 5" />
<TextBlock Text="Some Text 6" />
</StackPanel>
<StackPanel Name="stackPanel4" Grid.Row="3">
<TextBlock Text="SomeText 7" />
<TextBlock Text="Some Text 8" />
</StackPanel>
</Grid>
</UserControl>
你可以用它在你的看法是这样的:
<Page
x:Class="App1.MainPage"
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:local="using:App1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<local:ReusableCode x:Name="ucReusableCode" />
</Grid>
</Page>
如果你的用户控件位于你必须将其导出这样的文件夹内。
xmlns:usercontrol="using:App1.UserControlsFolder"
你是哪个XAML页内,可以这样调用:
<Page
x:Class="App1.MainPage"
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:local="using:App1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:usercontrol="using:App1.UserControlsFolder"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<usercontrol:ReusableCode x:Name="ucReusableCode" />
</Grid>
</Page>
希望这回答了你的问题。
SO不想N合1的问题,其中n> 1。而你的第一个问题,真的是很有限的用途。您不会根据使用频率来选择控件。你有要求并选择最佳匹配。鉴于所提供的信息,第二个问题是无法回答的。 – IInspectable
@IInspectable你好,因为第一个是“真/假”的问题,我认为这是毫无意义的创造另一个问题,对不起 – GuiPetenuci
的第一个问题是没有意义的要求,无论它是另一个问题的一部分,或立场 - 单独的问题。询问任何特定控制的受欢迎程度是毫无意义的。选择符合您要求的那个。如果你不知道你的要求,你应该回到绘图板。 – IInspectable