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

The Archive Base Latest Questions

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

I am creating a application, in which i have 2 user control, is it

  • 0

I am creating a application, in which i have 2 user control,
is it possible that, we have 2 xaml user control page and having 1 code behind xaml.cs file?

  • 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-23T11:42:39+00:00Added an answer on May 23, 2026 at 11:42 am

    Start off by creating three files, first the “code-behind” .cs file is created as a simple class:-

     public class MyCommonUserControl : UserControl
     {
    
     }
    

    Note it has no InitializeComponent call.

    Now create a new UserControl then modify its xaml to look like this:-

    <local:MyCommonUserControl x:Class="YourApp.FirstMyCommonUserControl "
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:YourApp"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
    
        </Grid>
    
    </local:MyCommonUserControl >
    

    Note the addition the xmlns:local alias to point to your app’s namespace then the change of the UserControl tag to the base control we actually want.

    You would modify the .xaml.cs to this:-

    public partial class FirstMyCommonUserControl : MyCommonUserControl 
    {
        public FirstMyCommonUserControl()
        {
            InitializeComponent();
        }
    }
    

    That is all the .xaml.cs needs to contain.

    You can then repeat this for SecondMyCommonUserControl and so on. Place all the common code in the base MyCommonUserControl class.

    Its a pity MS didn’t anticipate this in the first place, adding an empty virtual InitializeComponent method to the underlying UserControl and having the .g.i.cs auto-generated code override the method would have meant that we could dispense with this superflous .xaml.cs file in these cases.

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

Sidebar

Related Questions

I'm creating a wpf user control which is in mvvm pattern. So we have
I am creating one application with jquery.mobile-1.0a4.1 release. I have a page which is
I am creating Ribbon Control for my application and for which I have already
I am creating an application in which I have two mxml components, MainPanel.mxml and
I'm creating an application (Windows Form) that allows the user to take a screenshot
I am creating a application which displays 8 thumbnails per page and it can
I'm creating a WPF MVVM application. I have a long process that I want
I am creating a master page for admin-side of my application, which is using
I have an application which tab page based. To decrease the startup time I
I have custom view in my application which can be scrolled by the user.

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.