1
votes

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

1

1 Answers

2
votes

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}" />