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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:41:14+00:00 2026-06-12T05:41:14+00:00

I have a non-MVVM application. In the MainWindow, I have a TabControl with several

  • 0

I have a non-MVVM application. In the MainWindow, I have a TabControl with several tabs, and each tab contains a UserControl. Because those UserControls have similar features, I derive them from a base class that inherits from UserControl. Each of the UserControls has a TextBox called EdiContents. And each of them has a button:

<Button Name="Copy" Content="Copy to Clipboard" Margin="10" Click="Copy_Click" />

I would like to implement Copy_Click in the base UserControl class:

private void Copy_Click(object sender, RoutedEventArgs e)
{
    System.Windows.Forms.Clipboard.SetText(EdiContents.Text);
}

But the base class doesn’t know EdiContents TextBox, which is declared in each UserControl’s XAML. Could you please suggest how this can be solved?

Thanks.

  • 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-12T05:41:15+00:00Added an answer on June 12, 2026 at 5:41 am

    You can do something like this.

    public partial class DerivedUserControl : BaseUserControl
    {
        public DerivedUserControl()
        {
            InitializeComponent();
            BaseInitComponent();
        }
    }
    

    Note that you are calling BaseInitComponent after InitializeComponent

    XAML behind for derived control

    <app:BaseUserControl x:Class="WpfApplication5.DerivedUserControl"
                         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                         xmlns:app="clr-namespace:WpfApplication5"
                         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                         >
        <Grid>
            <Button Name="CopyButton"/>
        </Grid>
    </app:BaseUserControl>
    

    In your BaseUserControl::BaseInitComponent you simply lookup the button by name and wire up the event.

    public class BaseUserControl : UserControl
    {
        public void BaseInitComponent()
        {
            var button = this.FindName("CopyButton") as Button;
            button.Click += new System.Windows.RoutedEventHandler(Copy_Click);
        }
    
        void Copy_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            //do stuff here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple viewModels in my application and am binding/used them in ViewModelLocator mvvm
I have symlinks to certain directories because the directories' names have non English characters
I am creating a page-based WPF application using MVVM. I have created a custom
I have a C# WPF application using a rather noddy MVVM approach. In one
I am developing a WPF application (using MVVM) and have implemented IDataErrorInfo on my
I'd like to have non-uniform point sizes in matplotlib (set a size for each
I have a wpf usercontrol that contains an activex control housed in a windowsformhost.
I have non-ascii chars in velocity template files. And when processed they are garbled.
I have non-template class with a templatized constructor. This code compiles for me. But
I have a non ode function that calculates based on the previous time step

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.