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

  • SEARCH
  • Home
  • 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 6128539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:38:18+00:00 2026-05-23T16:38:18+00:00

When I create a custom control in WPF and add it to a window,

  • 0

When I create a custom control in WPF and add it to a window, I don’t see anything where I placed it in the dialog. Here’s what I’m doing:

  1. Create a new WPF Application
  2. Add -> New Item… -> Custom Control (WPF): “CustomButton.cs”
  3. I change the CustomButton base class to Button instead of Control
  4. Add a CustomButton control to my main window.
  5. When I run the application or view the main window in the designer, I don’t see anything.

Here’s what the code looks like.

CustomButton.cs:

public class CustomButton : Button
{
    static CustomButton()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomButton),
            new FrameworkPropertyMetadata(typeof(CustomButton)));
    }
}

MainWindow.xaml:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:WpfApplication1">
    <Grid>
        <my:CustomButton Content="Hello World" x:Name="customButton1"
                         HorizontalAlignment="Left" VerticalAlignment="Top" Margin="150,175,0,0" />
    </Grid>
</Window>

Generic.xaml:

<Style TargetType="{x:Type local:CustomButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:CustomButton}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I’ve found two leads as to what’s going on, but nothing has clicked yet. When I added the custom control, Visual Studio added Themes/Generic.xaml, but no matter what I try in there, I see no difference on screen. The other thing is that if I comment out the static constructor in CustomButton.cs, all of a sudden the button show up in the main window. It doesn’t look quite right in all situations, though (like if I use the button in a toolbar).

  • 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-05-23T16:38:18+00:00Added an answer on May 23, 2026 at 4:38 pm

    Where is your custom control template?

    By saying

          DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomButton),
            new FrameworkPropertyMetadata(typeof(CustomButton)));
    

    you’re indicating you want to defined your own custom control. I think if you remove that, you’ll see your button.

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

Sidebar

Related Questions

I know how to create a custom user control in WPF but how can
When creating a Navigation Application in WPF, How can I create a custom style
I am trying to create a custom wpf control, I'm wondering how I can
When I create a custom WPF control, I usually retain the usual default appearance
I want to create custom WPF control that has a single child control inside.
I'd like to create a custom WPF control using generics: public class MyGenericTypeControl<T> :
I am creating paint like application using WPF. Now i need to create control
I've got a custom composite WPF control (AvalonEdit) in my application that I'd like
Does anyone sell custom WPF controls on a per control basis? I don't want
I want to create a custom control in C#. But every time I have

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.