Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Databind to a CLR object with Source different to path
    primarykey
    data
    text
    <p>I am trying to update a textblock on the view by databinding to a property in the viewmodel (the datacontext for the view).</p> <p>In the code below; when <strong>SelectedItem</strong> changes, I want the textblock text to update with the value of the <strong>Name</strong> property on <strong>SelectedItem</strong>. </p> <p>In an attempt to achieve this I have set the <strong>binding source</strong> to the property that is changing and the <strong>binding path</strong> to the data I want to update the textblock with. </p> <p>I.e. I am expecting that the binding engine will see a change on the binding Source (SelectedItem) and pull the data from the binding Path (SelectedItem.Name).</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms746695.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms746695.aspx</a></p> <p>Setting the SelectedItem raises INPC but the text does not update.</p> <pre><code>public class ViewModel { public IConfiguration Configuration { get; set;} } public class Configuration : IConfiguration, INotifyPropertyChanged { public Item SelectedItem { get { return _item;} set { _item = value; ItemName = _item.Name; RaisePropertyChangedEvent("SelectedItem"); } } public string ItemName { get { return _itemName;} set { _itemName= value; RaisePropertyChangedEvent("ItemName"); } } } public class Item { public string Name { get; set;} } </code></pre> <p>I know that changes on Configuration are seen because this works:</p> <pre><code>&lt;TextBlock Text="{Binding Configuration.ItemName}"/&gt; </code></pre> <p>But this does not:</p> <pre><code>&lt;TextBlock Text="{Binding Path=Name, Source=Configuration.SelectedItem}"/&gt; </code></pre> <p>And nor does this:</p> <pre><code>&lt;TextBlock Text="{Binding Path=Configuration.SelectedItem.Name, Source=Configuration.SelectedItem}"/&gt; </code></pre> <p>I'm assuming that this should be straightforward - what have I missed?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload