locked
Binding a property of a property RRS feed

  • Question

  • I have o1 in the DataContext and i want to binding a property of a control to:

    o1.p1.p2

    Can i do this in the XAML?

    Thanks in advance
    Monday, November 3, 2008 2:23 PM

Answers

  • You can bind to the property of a datacontext by setting the property name in the binding.

    For example, the following syntax can be used to bind to properties and properties of the properties of an object set through the DataContext:

    <StackPanel DataContext="{Binding}">                <!-- Set to Object1 --> 
      <TextBlock Text="{Binding Name}"/>              <!-- binds to Name property of Object1 --> 
      <TextBlock Text="{Binding Accounts.Count}"/>    <!-- Binds to Count property of the Accounts property of Object1 --> 
    </StackPanel> 
     


    Hope this helps,
    Brian
    Brian Schwalm • www.anythinksolutions.com
    Monday, November 3, 2008 6:17 PM

All replies

  • You can bind to the property of a datacontext by setting the property name in the binding.

    For example, the following syntax can be used to bind to properties and properties of the properties of an object set through the DataContext:

    <StackPanel DataContext="{Binding}">                <!-- Set to Object1 --> 
      <TextBlock Text="{Binding Name}"/>              <!-- binds to Name property of Object1 --> 
      <TextBlock Text="{Binding Accounts.Count}"/>    <!-- Binds to Count property of the Accounts property of Object1 --> 
    </StackPanel> 
     


    Hope this helps,
    Brian
    Brian Schwalm • www.anythinksolutions.com
    Monday, November 3, 2008 6:17 PM
  • this posting is a duplicate of :
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/88e23ed5-ae82-4f13-bd8d-9c098532b887
    Monday, November 3, 2008 6:24 PM