Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I initialize a XAML UserControl with fake data design-time when working with the control itself?
    text
    copied!<p>I have a basic WinRT XAML UserControl with a single dependency property as implemented below. The user control is apparently only constructed design-time when used in another Page or UserControl. The text "Hello world" is not rendered when I work in the designer with the user control itself. How can I make the designer initialize the user control with data also in this case?</p> <p>XAML:</p> <pre><code>&lt;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"&gt; &lt;Grid Background="Black"&gt; &lt;TextBlock Text="{Binding Path=Message, ElementName=ThisControl}" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="280" Width="380"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Code-behind:</p> <pre><code>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"; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload