我有一个基本的 WinRT XAML UserControl,它具有如下实现的单个依赖项属性。用户控件显然只有在另一个 Page 或 UserControl 中使用时才在设计时构建。当我在设计器中使用用户控件本身工作时,不会呈现文本“Hello world”。在这种情况下,如何让设计器也用数据初始化用户控件?
XAML:
<UserControl
x:Class="GTWin8.Ui.SimpleBinding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GTWin8.Ui"
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"
x:Name="ThisControl">
<Grid Background="Black">
<TextBlock Text="{Binding Path=Message, ElementName=ThisControl}"
HorizontalAlignment="Left" Margin="10,10,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" Height="280" Width="380"/>
</Grid>
</UserControl>
代码隐藏:
public sealed partial class SimpleBinding : UserControl
{
public static DependencyProperty MessageProperty = DependencyProperty.Register(
"Message", typeof(String), typeof(SimpleBinding), new PropertyMetadata(null));
public String Message
{
get { return (String)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public SimpleBinding()
{
this.InitializeComponent();
Message = "Hello world";
}
}