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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:05:39+00:00 2026-06-10T15:05:39+00:00

I have a User Control Library that I am loading dynamically. From that lib

  • 0

I have a User Control Library that I am loading dynamically. From that lib I am inserting a Tabitem into a TabControl. I can load the tab and show it without error. However, I can’t seem to get the binding on the control working.

This is the code I use to load it and add it to the TabControl:

    Assembly moduleAssembly = Assembly.Load("ControlLib");            
    UserControl uc = (UserControl)Application.LoadComponent(new System.Uri("/ControlLib;component/UserControl1.xaml", UriKind.RelativeOrAbsolute));
    TabControl itemsTab = (TabControl)this.FindName("mainTabControl");
    TabItem newTab = new TabItem();
    newTab.Content = uc;
    newTab.Header = "Test";
    itemsTab.Items.Add(newTab);
    itemsTab.SelectedItem = newTab;

This is the C# code for the control:

public partial class UserControl1 : UserControl
{        
    public static readonly DependencyProperty TestStringProperty = 
        DependencyProperty.Register("TestString", typeof(string), typeof(UserControl1));

    public string TestString { get; set; }

    public UserControl1()
    {
        InitializeComponent();

        TestString = "Hello World";
    }
}

This is the XAML code for the control:

<UserControl x:Class="ControlLib.UserControl1"
             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>        
        <TextBox Height="30" Width="100" HorizontalAlignment="Left" VerticalAlignment="Bottom" Text="{Binding Path=TestString, Mode=TwoWay}" />
    </Grid>
</UserControl>

When the tab displays all I see if a blank in the TextBox rather than “Hello World”

What am I missing?

  • 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-10T15:05:40+00:00Added an answer on June 10, 2026 at 3:05 pm

    You would still be setting the DataContext of your user control to instance of the class. Just how you go about creating that instance differs as you would be loading that dll a runtime. But fundamentally the binding setup remains the same.

        var assembly = Assembly.LoadFrom(@"yourdllname.dll");
        Type type = assembly.GetType("ClassLibrary1.SampleViewModel"); 
        object instanceOfMyType = Activator.CreateInstance(type);
    
        DataContext = instanceOfMyType;
    

    For how basic databinding works read MSDN documentation.

    Make sure you select the correct framework on the top of the screen.

    EDIT

    Usually this is created as a separate class (ViewModel in MVVM pattern).

     public partial class Window3 : Window, INotifyPropertyChanged
        {
            public Window3()
            {
                InitializeComponent();
    
                DataContext = this;
                TestString = "Hello World.";
            }
    
            string _testString;
            ///<summary>Gets or sets TestString.</summary>            
            public string TestString
            {
                get { return _testString; }
                set { _testString = value; OnPropertyChanged("TestString"); }
            }
    
    
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            public void OnPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                {
                    var e = new PropertyChangedEventArgs(propertyName);
                    PropertyChanged(this, e);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an user control in our library that I need to inherit and
I have built a User Control library that has a reference to a WCF
I have an User Control that host another controls like panel, chart controls. Right
I have a user control that is being integrated to the page on run
I am new to WPF and have created a WPF User Control Library I
I want to have a common control library with a whole bunch of User
I have a compiled class library containing a user control and I'd like to
I have made a control library and two user controls. userControl_1 contains a Panel
I have a library that serves using events data came in from async tcp
I have a function to load a user control, it looks like this: private

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.