silverlightmvvmsilverlight-5.0

Silverlight pass DataContext to ConverterParameter?


How can I pass the DataContext of LayoutRoot to the converter of the ContentControl inside the ListBox items template?

<Grid x:Name="LayoutRoot"
  Background="White"
  DataContext="{Binding Source={StaticResource myViewModel}}">
    <StackPanel HorizontalAlignment="Left"
          Margin="6,6,0,394"
          Orientation="Vertical"
          Width="200"
          d:LayoutOverrides="Height">
    <ListBox x:Name="listBox2"
         ItemsSource="{Binding MyCollection, Mode=TwoWay}"
         VerticalAlignment="Top"
         Height="400">

       <ListBox.ItemTemplate>
          <DataTemplate>
             <ContentControl Content="{Binding}"
                      ContentTemplate="{Binding Converter={StaticResource  myConverter}}"/>
          </DataTemplate>
       </ListBox.ItemTemplate>
      </ListBox>
     <TextBox Text="{Binding Value1, Mode=TwoWay}"/>
    </StackPanel>
</Grid>

I want to be able to touch the objects inside the DataContext from within the Converter and use them for TwoWay binding on controls within the ListBox item's DataTemplate.

Any ideas? Any suggestions?

Thank you.


Solution

  • I just got the DataContext up to the converter using:

    <ContentControl Content="{Binding}"
                    ContentTemplate="{Binding Converter={StaticResource stringToDataTemplateConverter}, ConverterParameter={StaticResource myViewModel}}" />
    

    Now I have another problem my dynamic property binding is not working.