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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:09:17+00:00 2026-06-17T15:09:17+00:00

I’m trying to bind a string to my textbox control, but the string is

  • 0

I’m trying to bind a string to my textbox control, but the string is buried away.

The code I want to use is the following contrived example

namespace BackUps.Logging.ViewModel
{
    class Obj1
    {
        public Obj2 obj2 { get; set; }
    }

    class Obj2
    {
        public Obj3 obj3 { get; set; }
    }

    class Obj3
    {
        public string Message 
        {
           get { return "Hello World"; }
        }
}

My VM looks like

namespace BackUps.Logging.ViewModel
{
    internal class LogsVM
    {
       public Obj1 Obj1 { get; private set; }

    public LogsVM()
    {
          Obj1 = new Obj1();
    }
}

My question is, how can I bind the Message to the TextBlock with Xaml? This is what I have:

   <Window x:Class="BackUps.Logging.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:myData ="clr-namespace:BackUps.Logging.ViewModel"
        Title="Logging Results" Height="350" Width="525">

    <Grid DataContext="{x:Type myData:LogsVM}">
        <TextBlock Text="{Binding Message}" />
    </Grid>
</Window>

The above doesn’t work. Nor does

<TextBlock Text="{Binding Obj1.Message}" />

or

<TextBlock Text="{Binding Obj1.Obj2.Obj3.Message}" />

I know this example is daft, but there are many times when a class’s properties is a List type, and within that List is another etc, and knowing how to drill down to a specific property, no matter how many layers deep is important but I’ve gotten no where finding out how.

  • 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-17T15:09:19+00:00Added an answer on June 17, 2026 at 3:09 pm

    This works assuming the datacontext is your viewmodel:

    <Window x:Class="WpfGridColumns.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" SizeToContent="WidthAndHeight"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            mc:Ignorable="d"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:wpfGridColumns="clr-namespace:WpfGridColumns"
            d:DataContext="{d:DesignInstance Type=wpfGridColumns:LogsVM, IsDesignTimeCreatable=True}"
            >
        <Grid>
            <TextBox Text="{Binding Obj1.obj2.obj3.Message}" />
        </Grid>
    </Window>
    

    You can set up designtime data using this syntax:

    d:DataContext="{d:DesignInstance Type=wpfGridColumns:LogsVM, IsDesignTimeCreatable=True}"

    It gives Intellisense in the VS designer and is helpful when placing bindings.

    I used this code behind:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new LogsVM();
        }
    }
    
    internal class LogsVM
    {
        public Obj1 Obj1 { get; private set; }
    
        public LogsVM()
        {
            Obj1 = new Obj1();
        }
    }
    
    public class Obj1
    {
        public Obj1()
        {
            obj2=new Obj2();
        }
        public Obj2 obj2 { get; set; }
    }
    
    public class Obj2
    {
        public Obj2()
        {
            obj3= new Obj3();
        }
        public Obj3 obj3 { get; set; }
    }
    
    public class Obj3
    {
        public Obj3()
        {
            Message = "Test";
        }
        public string Message { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i got an object with contents of html markup in it, for example: string
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.