Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes VS2010 show data in UserControls during design time?
    primarykey
    data
    text
    <p>I have a trivial user control:</p> <pre><code>&lt;UserControl x:Class="Xxx.SimpleUserControl.SimpleTextUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="root"&gt; &lt;StackPanel Background="Blue"&gt; &lt;TextBlock x:Name="TitleTextBlock" Text="{Binding ElementName=root, Path=Title}" Background="White" Width="200" Height="30" Margin="5" /&gt; &lt;TextBlock Text="{Binding ElementName=root, Path=Time}" Background="White" Width="200" Height="30" Margin="9" /&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>and the code behind:</p> <pre><code>using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; namespace Xxx.SimpleUserControl { /// &lt;summary&gt; /// Interaction logic for UserControl1.xaml /// &lt;/summary&gt; public partial class SimpleTextUserControl : UserControl { public SimpleTextUserControl() { InitializeComponent(); } [Browsable(true)] [Category("SimpleControl")] public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } // Using a DependencyProperty as the backing store for Title. This enables animation, styling, binding, etc... public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(SimpleTextUserControl), new FrameworkPropertyMetadata("hello")); [Browsable(true)] [Category("SimpleControl")] public DateTime Time { get { return (DateTime)GetValue(TimeProperty); } set { SetValue(TimeProperty, value); } } // Using a DependencyProperty as the backing store for Time. This enables animation, styling, binding, etc... public static readonly DependencyProperty TimeProperty = DependencyProperty.Register("Time", typeof(DateTime), typeof(SimpleTextUserControl), new UIPropertyMetadata(DateTime.Now)); } } </code></pre> <p>I naively expect the VS2010 designer for the UserControl to display my default metadata values for my two controls - "hello" in one textblock, and today's date and time in other, but they are empty.</p> <p>If I compile, and drop the control in to a WPF application, it renders fine, but not whilst in the UserControl project xaml view/designer.</p> <p>I've tried changing the datacontext around, binding in different ways, implementing OnPropertyChanged etc., but nothing makes the data render in the UserControl project's design view.</p> <p>Does anyone know the answer to this one? I've searched around, and either it's so obvious I'm missing it, or it's 'just the way it is'.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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