Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8828977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:43:46+00:00 2026-06-14T07:43:46+00:00

I am currently writing a Dialog class (lookless control) which extends Window, and am

  • 0

I am currently writing a Dialog class (lookless control) which extends Window, and am assigning a default ControlTemplate to that class using a XAML style.

I want the ‘Buttons’ section of my Dialog template to be replacable, yet pre-populate it with a set of default buttons if nothing else is specified. This is why I added a dependency property called ButtonContent to my class.

The DefaultButtons (see XAML below) are rendered correctly when I run the application, but Visual Studio 2010’s design preview does not render the content. Why is this not happening?

My dialog class looks like this:

public class Dialog : Window
{
    public FrameworkElement ButtonContent
    {
        get { return (FrameworkElement)GetValue(ButtonContentProperty); }
        set { SetValue(ButtonContentProperty, value); }
    }

    public static readonly DependencyProperty ButtonContentProperty =
        DependencyProperty.Register("ButtonContent", typeof(FrameworkElement), typeof(Dialog), new UIPropertyMetadata(null));

    static Dialog()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(Dialog), new FrameworkPropertyMetadata(typeof(Dialog)));
    }
}

This is my XAML:

<Style TargetType="{x:Type Dialogs:Dialog}">
    <Setter Property="DataContext" Value="{Binding RelativeSource={RelativeSource Self}}"/>     
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Dialogs:Dialog}">
                <StackPanel>
                    <ContentPresenter Content="{TemplateBinding ButtonContent}"/>
                    <TextBlock>This text is rendered correctly</TextBlock>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="ButtonContent">
        <Setter.Value>
            <!-- This stuff here is not shown in VS2010's preview -->
            <UniformGrid Name="DefaultButtons" Rows="1" Columns="2">
                <Button>Button 1</Button>
                <Button>Button 2</Button>
            </UniformGrid>
        </Setter.Value>
    </Setter>
</Style>

When I launch the app, it looks like this:

As rendered by the app

The VS2010 designer renders this:

As rendered by VS2010


Edit: As described in the comments, placing the above style in Themes\Generic.xaml instead of my resource dictionary included from App.xaml does not change anything.


Edit 2: If I explicitly override the default ButtonContent like this, the designer also does not show anything. At runtime, everything works perfectly:

<Dialogs:Dialog x:Class="Dialogs.TestDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Dialogs="clr-namespace:Dialogs">
    <Dialogs:Dialog.ButtonContent>
        <Button>Also not shown at design time</Button>
    </Dialogs:Dialog.ButtonContent>
</Dialogs:Dialog> 

Edit 3: If I add the ButtonContent property to a UserControl instead of my Dialog class that extends Window, the ButtonContent is displayed correctly within the user control… also, VS2010 seems to apply the style defined above to any window, not just those of class Dialog, although I have set the TargetType appropriately… weird!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:43:47+00:00Added an answer on June 14, 2026 at 7:43 am

    I opened up a bug report at Microsoft Connect for this issue. According to MS, it is a known issue and is by design:

    Thanks for reporting this issue. This is a known issue on our end and is by design. We cannot create a design instance of Window within the designer so we substitute with a proxy type of our own. That is the reason why it works correctly in a UserControl and not in a window. The workaround is to design the content of the dialog separately as a UserControl.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a program using Weka that builds a model (using one
I'm currently writing a small python app that embeds cherrypy and django using py2app.
I'm currently writing a simple app that performs a series of requests to the
I'm currently writing a function what would create a zip file, which will be
I am currently writing a simple IOS app that saves tasks into a table.
I'm currently writing a billing application using EF 5 Code First, and I'm running
I'm currently writing a Powershell script that's used to select a user from Active
I'm currently writing several Python modules which perform some I/O. Thoses modules can be
I am currently writing a script which parses the ServiceTage, Computername and Username from
I'm currently writing a live wallpaper for Android and it has a PreferenceScreen which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.