I\'m updating some existing WPF code and my application has a number of textblocks defined like this:
Try this:
In code:
public MyBusinessObject Instance { get; set; }
Instance = new MyBusinessObject();
In XAML:
<TextBlock Text="{Binding Instance.PropertyNameHere" />
Try to instantiate ObjectA in the same way as you are doing for PropertyA (Ie. as a property, with a public getter / setter, and calling OnPropertyChanged), then your XAML can be :
<TextBlock Text="{Binding ObjectA.PropertyNameHere}" />
Before <Run Text="{Binding ObjectA.PropertyNameHere}" /> will work you have to make ObjectA itself a property because binding will only work with properties not fields.
// my business object also contains another object like this
public SomeOtherObject ObjectA { get; set; }
public MyBusinessObject()
{
// constructor
ObjectA = new SomeOtherObject();
}
You can simply type this:
<TextBlock Text="{Binding ObjectA.PropertyNameHere"/>
You may want to implement INotifyPropertyChanged within your ObjectA class, as changing properties of the class will not be picked up by the PropertyChanged methods in your MyBusinessObject class.
You can do a same as you do for PropertyA like follows,
OnPropertyChanged(new PropertyChangedEventArgs("ObjectA"));
on Designer XAML,
<TextBlock x:Name="ObjectAProperty" Text="{Binding ObjectA.PropertyNameHere}" />