locked
Binding to DataContext in Blend 3 RRS feed

  • Question

  • Hi guys,

    i'm trying to build a simple application, that changes images based on Selected item in ListBox.

    <Grid>
    
          <Grid>
                 <Image/>
          </Grid>
          <ListBox/>
    </Grid>

    The XAML looks similar to this. ListBox's Item are taken from XML DataSource.

    I set DataContext of the "inside" Grid to the ListBox's SelectedItem property. The problem is that when i try to DataBind Image source property to the one from DataContext, i am not seeing anything in the "Explicit Data Context" pane. Help please.

    Wednesday, March 31, 2010 6:51 PM

Answers

  • If you set the d:DataContext property on the Grid to an object like so, things should work (this is what our master/detail builder does internally):

    <Grid DataContext="{Binding SelectedItem, ElementName=listBox}" d:DataContext="{Binding Collection[0]}">

    Alternatively, I am curious how your project looks like - for me, if was to use just the sample data feature of Blend 3 to define this master/detail relationship, this should have worked even without d:DataContext. We should have been able to figure out the type of the object from the SelectedItem of the ListBox (or more precisely, ItemsSource of the ListBox).

    Thanks
    Unni


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, April 1, 2010 1:54 AM