这取决于你想要走的路,取决于你是否想要把一个资源存档,备有某些模板等,这些模板被适当复制/连接到每项申请中,或者使用共同的DL中包含的内容。
If you want to do the latter, here s one approach. Subclass ContentControl
to define your common layout in its control template (you can do this all in XAML), including a binding to its Content in the appropriate place:
<ContentControl x:Class="MyLibrary.MyLayoutControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ContentControl.Template>
<ControlTemplate TargetType="ContentControl">
<!-- this could be a layout grid with various other controls in it -->
<Border BorderBrush="Red" BorderThickness="2" CornerRadius="5">
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
</ControlTemplate>
</ContentControl.Template>
</ContentControl>
Then use it in your application root control:
<UserControl x:Class="InCustomControlTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:MyLibrary;assembly=MyLibrary">
<c:MyLayoutControl>
<Button Content="Hi I am a button" />
</c:MyLayoutControl>
</UserControl>
如果你想做一些更复杂的事,那么你就应当进行习俗控制;尽管在大多数情形下,你可能能够放弃几个用户对你们进入正确位置的各个组成部分(例如,你的地位酒吧)的看法。