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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:48:36+00:00 2026-06-02T05:48:36+00:00

Say for example I have the following type: public class Site { public string

  • 0

Say for example I have the following type:

    public class Site
    {
       public string Name { get; set; }
       public int SiteId { get; set; }
       public bool IsLocal { get; set; }
    }

The above type can be assigned to be held in a Propety in a ViewModel like so assuming a corresponding backing field has been created but omitted here ofc:

    public Site SelectedSite
    {
        get { return _selectedSite; }
        set
        {
            _selectedSite = value;
            // raise property changed etc
        }
    }

In my xaml a straight forward binding would be:

            <TextBlock x:Name="StatusMessageTextBlock"
                   Width="Auto"
                   Height="Auto"
                   Style="{StaticResource StatusMessageboxTextStyle}"
                   Text="{Binding MessageToDisplay,
                                  Mode=OneWay,
                                  UpdateSourceTrigger=PropertyChanged}" />

Can you extend a binding by using the dot notation syntax? e.g:

            <TextBlock x:Name="StatusMessageTextBlock"
                   Width="Auto"
                   Height="Auto"
                   Style="{StaticResource StatusMessageboxTextStyle}"
                   **Text="{Binding SelectedSite.Name,**
                                  Mode=OneWay,
                                  UpdateSourceTrigger=PropertyChanged}" />

Seems like a an interesting feature but my gut instinct is a no as my DC is being assigned at RunTime so at DesignTime or CompileTime, I can’t see any clues that could make this feature work or not?

Correct me if have misunderstood what a complex object is, I have simplified mine down for the sake of this question.

  • 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-02T05:48:37+00:00Added an answer on June 2, 2026 at 5:48 am

    Of course this is possible. However, WPF needs to know when any property along the path has changed. To that end, you need to implement INotifyPropertyChanged (or other supported mechanisms). In your example, both Site and the VM containing SelectedSite should implement change notification).

    Here’s how you could implement the functionality you specified in your question:

    // simple DTO
    public class Site
    {
       public string Name { get; set; }
       public int SiteId { get; set; }
       public bool IsLocal { get; set; }
    }
    
    // base class for view models
    public abstract class ViewModel
    {
        // see http://kentb.blogspot.co.uk/2009/04/mvvm-infrastructure-viewmodel.html for an example
    }
    
    public class SiteViewModel : ViewModel
    {
        private readonly Site site;
    
        public SiteViewModel(Site site)
        {
            this.site = site;
        }
    
        // this is what your view binds to
        public string Name
        {
            get { return this.site.Name; }
            set
            {
                if (this.site.Name != value)
                {
                    this.site.Name = value;
                    this.OnPropertyChanged(() => this.Name);
                }
            }
        }
    
        // other properties
    }
    
    public class SitesViewModel : ViewModel
    {
        private readonly ICollection<SiteViewModel> sites;
        private SiteViewModel selectedSite;
    
        public SitesViewModel()
        {
            this.sites = ...;
        }
    
        public ICollection<SiteViewModel> Sites
        {
            get { return this.sites; }
        }
    
        public SiteViewModel SelectedSite
        {
            get { return this.selectedSite; }
            set
            {
                if (this.selectedSite != value)
                {
                    this.selectedSite = value;
                    this.OnPropertyChanged(() => this.SelectedSite);
                }
            }
        }
    }
    

    And your view might look something like this (assuming a DataContext of type SitesViewModel):

    <ListBox ItemsSource="{Binding Sites}" SelectedItem="{Binding SelectedSite}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say suppose I have the following Java code. public class Example { public static
Let's say I have the following two classes: package example.model; public class Model {
Say for example I have the following string: var testString = Hello, world; And
This is for Delphi Prism. Say, I have the following enum SET type that
Let's say that I have the following delegate: public delegate void Example(); and a
I have a generic list of type Element , for example. public class Element
Let's say for example i have URL containing the following percent encoded character :
Say for example, I have the following two tables: TableA { _id } TableB
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
I do not understand the following example, let's say I have these functions: #

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.