因为在UWP应用程序中没有布局继承形式,所以必须使用CustomControl作为布局的基础。
如何在UWP应用程序中将CustomControl用作设计模式中的放置目标?因此,从设计调色板中删除的按钮将包含在CustomControl中。
我能找到的所有文档都与WPF应用有关,并不适用于UWP应用。
非常感谢任何完整的例子。
答案 0 :(得分:0)
XAML:
<UserControl x:Name="userControl"
x:Class="Ids2.ProgramBaseLayout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Ids2"
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" Style="{Binding Source={StaticResource programBaseLayoutStyle}}"
>
<Grid Background="{Binding ContentAreaBackground, ElementName=userControl}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="9*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="0" TextWrapping="Wrap" Text="{Binding Title, ElementName=userControl}" VerticalAlignment="Top" MinWidth="30"/>
<Frame x:Name="frame" Margin="0" Grid.Row="1"/>
</Grid>
</UserControl>
守则:
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace Ids2
{
public sealed partial class ProgramBaseLayout : UserControl
{
public ProgramBaseLayout()
{
InitializeComponent();
}
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(ProgramBaseLayout), null);
public Brush ContentAreaBackground
{
get { return (Brush)GetValue(ContentAreaBackgroundProperty); }
set { SetValue(ContentAreaBackgroundProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ContentAreaBackgroundProperty =
DependencyProperty.Register("ContentAreaBackground", typeof(Brush), typeof(ProgramBaseLayout), null);
}
}
当一个按钮掉落时,它不会在框架内部结束,最终会在控件顶部结束。
如果掉落仅限于掉落在帧内,那将是很好的。