Note that there are some explanatory texts on larger screens.

plurals
  1. POIn WPF, how do I give my custom control a default style to be used in Design Mode?
    primarykey
    data
    text
    <p>I have created a custom WPF control. The control acts as a container with various regions (so it can work like a master page).</p> <p>The style for this control is loaded at runtime from a separate resource dictionary as follows:</p> <pre><code>&lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="/MyApp.Application;component/Themes/Theme.xaml" x:Name="theme"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; </code></pre> <p>My custom control's style looks as follows...</p> <pre><code>&lt;Style TargetType="{x:Type shareduc:EditControlMaster}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type shareduc:EditControlMaster}"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt;&lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="*"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;Border BorderBrush="{DynamicResource xxBorderBrush}" BorderThickness="0,1,0,1" Background="White" Grid.Row="0"&gt; &lt;Grid &gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="auto"&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition Width="*"&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;ContentPresenter Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Margin="10" Content="{TemplateBinding Image}" /&gt; &lt;ContentPresenter Grid.Row="0" Grid.Column="1" Margin="2" Content="{TemplateBinding Title}" /&gt; &lt;ContentPresenter Grid.Row="1" Grid.Column="1" Margin="2" Content="{TemplateBinding Abstract}" /&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ContentPresenter Grid.Row="1" Margin="2" Content="{TemplateBinding Content}" /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>The problem is that this style is only loaded at Runtime. So in Design Mode my control does not have any style and does not have any size or layout. How can I give my control a default style for Design Mode?</p> <p><strong>Update</strong>: I'm making some progress... it appears I can specify a default theme to use in a file called Themes\Generic.xaml. This works fine in a small sample project, but for some reason my VS2008 designer stays blank when I do the same thing in my actual project... Help? :(</p> <p>Note that my custom control's code looks as follows:</p> <pre><code>public partial class EditControlMaster : Control { static EditControlMaster() { DefaultStyleKeyProperty.OverrideMetadata(typeof(EditControlMaster), new FrameworkPropertyMetadata(typeof(EditControlMaster))); } public object Title { get { return (object)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(object), typeof(EditControlMaster), new UIPropertyMetadata()); public object Image { get { return (object)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(object), typeof(EditControlMaster), new UIPropertyMetadata()); public object Abstract { get { return (object)GetValue(AbstractProperty); } set { SetValue(AbstractProperty, value); } } public static readonly DependencyProperty AbstractProperty = DependencyProperty.Register("Abstract", typeof(object), typeof(EditControlMaster), new UIPropertyMetadata()); public object Content { get { return (object)GetValue(ContentProperty); } set { SetValue(ContentProperty, value); } } public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(EditControlMaster), new UIPropertyMetadata()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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