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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:27:50+00:00 2026-06-02T09:27:50+00:00

I am making a simple demo to learn how to create a bindable user

  • 0

I am making a simple demo to learn how to create a bindable user control. I have created a simple class:

class Person
{
    public string firstName;
    public string lastName;    
    public Person(string first, string last)
    {
        firstName = first;
        lastName = last;
    }
}

And a very simple user control:

<UserControl x:Class="Example.ExampleHRControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock x:Name="textFirstName"></TextBlock>
        <TextBlock x:Name="textLastName"></TextBlock>
    </Grid>
</UserControl>

What I would like to know is what do I need to do in order to be able to use the user control in context like a normal control. I can add this to the MainWindow:

<local:ExampleHRControl x:Name="Hr1"></local:ExampleHRControl>

and then I can address it through code behind and add the value:

Hr1.textFirstName.Text = "John";
Hr1.textLasttName.Text = "Doe";

I would prefer to be able to create an instance of the class Person and simply bind the control on the main window to the Person class.

  • 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-02T09:27:51+00:00Added an answer on June 2, 2026 at 9:27 am

    A couple things you need to do to make this work.

    In your code-behind, add a dependency property for the Person object you want your control to know about:

       public static readonly DependencyProperty PersonProperty =
                              DependencyProperty.Register("Person", typeof(Person),
                                                          typeof(ExampleHRControl));
    
       public Person Person
       {
          get { return (Person)GetValue(PersonProperty); }
          set { SetValue(PersonProperty, value); }
       }
    

    In your XAML, set up your code-behind as your data context and add the binding to your person object:

    <UserControl x:Class="Example.ExampleHRControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="This">
        <Grid>
            <TextBlock x:Name="{Binding Path=Person.FirstName, ElementName=This}"/>
            <TextBlock x:Name="{Binding Path=Person.LastName, ElementName=This}"/>
        </Grid>
    </UserControl>
    

    Now, whenever the Person property is set, your control will update itself with the First and Last names that are associated to the Person.

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

Sidebar

Related Questions

I've created this simple demo because I'm having some trouble making auto-sizing work in
I've created a simple auto-complete control using JQuery UI. I have a default value
I'm making a simple WebGL demo. I have a simple vertex shader that takes
I'm making a simple program in Objective-C. It has one class with a lot
I was making a simple class for a small project and decided to just
I'm making a simple search form in rails. In my search view I have
i am making simple autosuggestion (autocompleter) plugin with jQuery. Unfortunately i have to use
Making a simple program which will generate a multiple choice form. I have an
I'm making a simple UI demo and need to assign the 0 on the
I'm making a simple MP3Player in Java. I have managed to play a .mp3

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.