您可以隨時使用舊的用戶控件。在這裏,我爲你提供了一個例子:
<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