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 385431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:28:45+00:00 2026-05-12T15:28:45+00:00

I can inherit and enhance the ToolBar class by creating a plain C# class,

  • 0

I can inherit and enhance the ToolBar class by creating a plain C# class, then doing this:

public class NiceToolBar : ToolBar
{
    private ToolBarTray mainToolBarTray;

    public NiceToolBar()
    {
        mainToolBarTray = new ToolBarTray();

        mainToolBarTray.IsLocked = true;
        this.Background = new SolidColorBrush(Colors.LightGray);
        ...

But this forces me to manipulate all my controls in code like this:

ToolBar toolBar = new ToolBar();
toolBar.Background = new SolidColorBrush(Colors.Transparent);
toolBar.Cursor = Cursors.Hand;

StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;

TextBlock tb = new TextBlock();
tb.Text = label;
tb.Margin = new Thickness { Top = 3, Left = 3, Bottom = 3, Right = 10 };

Image image = new Image();
image.Source = new BitmapImage(new Uri("Images/computer.png", UriKind.Relative));

sp.Children.Add(image);
sp.Children.Add(tb);
toolBar.Items.Add(sp);

What I really need is XAML to do this tedious parameter assigning and layout.

So I create a new User Control and change the code behind to inherit ToolBar like this:

public partial class SmartToolBar : ToolBar
{
    public SmartToolBar(string label)
    {
        InitializeComponent();

        TheLabel.Text = label;
    }
}

And in my XAML I put this:

<UserControl x:Class="TestUserControl.Helpers.SmartToolBar"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel Orientation="Horizontal">
        <Image Source="Images/computer.png"/>
        <TextBlock x:Name="TheLabel"/>
    </StackPanel>
</UserControl>

But when I run it, I get the error:

Partial declaration of
“TestCallConstructor.Helpers.SmartToolBar”
may not define different basis classes

How can I have my user control with XAML?

  • 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-12T15:28:45+00:00Added an answer on May 12, 2026 at 3:28 pm

    You are looking for Custom Controls (not UserControl). When you write a custom control you can specify its default view (i.e. XAML).

    You can google how to create custom controls in WPF, but here is one link I googled out for you How to Create a WPF Custom Control.

    Hope this helps :).

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

Sidebar

Related Questions

Today I happens to find that one C# class can inherit one interface both
I am trying to create a base class where I can inherit from it
When developing web parts in SharePoint can I inherit from the existing web parts
As just stated in a recent question and answer , you can't inherit from
Why can't I create a class in VB.NET that inherits System.IO.Directory ? According to
If an interface inherits IEquatable the implementing class can define the behavior of the
Everything inherits from object. It's the basis of inheritance. Everything can be implicitly cast
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through

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.