troubleshooting Question

Beginner -- how to make a XAML User Control Bindable

Avatar of VoodooFrog
VoodooFrogFlag for United States of America asked on
.NET ProgrammingC#
3 Comments1 Solution389 ViewsLast Modified:
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;

I created a very simple user control:  

<UserControl x:Class="Example.ExampleHRControl"
             d:DesignHeight="300" d:DesignWidth="300">
        <TextBlock x:Name="textFirstName"></TextBlock>
        <TextBlock x:Name="textLastName"></TextBlock>

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 like normal:

<local:ExampleHRControl x:Name="Hr1"></local:ExampleHRControl>
and then I can address it through c# 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 simple bind the control on the main window to the Person class.
Kyle Abrahams
Director of Information Technology

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros