user687554
user687554

Reputation: 11131

Nested DataContext in XAML in Silverlight

I have a UserControl in Silverlight. This UserControl looks like this:

<TextBlock Text="{Binding Path=OrderDate}" />
<TextBlock Text="{Binding Path=ShipDate}" />

I have a class that is defined as follows:

public class MyViewModel : ViewModel
{
  public string Description { get; set; }
  public string Origin { get; set; }

  public SlipDetails Details { get; set; }
}

This view model is populated and in the code-behind of my UserControl. I then use this.DataContext = myViewModel; to set the UserControl's DataContext. My problem is, I want to use relative binding in my details grid. I would like to be able to set the DataContext of "detailsGrid" in the XAML to the Details property. Is there a way to do this?

Thanks

Upvotes: 1

Views: 588

Answers (1)

Flawless
Flawless

Reputation: 127

I assume that the OrderDate and ShipDate are part of the SlipDetails class?

In that case, you can bind to those fields by using

<TextBlock Text="{Binding Path=Details.OrderDate}" />
<TextBlock Text="{Binding Path=Details.ShipDate}" />

Upvotes: 2

Related Questions