2012-03-02 7 views
1

ListBoxアイテムテンプレート内のContentControlのコンバーターにLayoutRootのDataContextを渡すにはどうすればよいですか?SilverlightはDataContextをConverterParameterに渡しますか?

<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> 

私は、コンバータ内からのDataContext内のオブジェクトに触れると双方向でのListBox項目のDataTemplateの内のコントロールにバインドするためにそれらを使用できるようにしたいです。

アイデア?助言がありますか?

ありがとうございます。

答えて

1

私はちょうど

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

私は動的プロパティのバインディングが機能していないという別の問題があります。

0

(私の悪い英語のため申し訳ありません)

私はあなたがここでやろうとしているかについてはよく分からないが、SL 5とあなたはDataContextのを取得するためにRelativeSourceを使用することができます。

{Binding DataContext,RelativeSource={RelativeSource AncestorLevel=1,AncestorType=Grid}} 
+0

それは動作しません:( – asuciu

+1

バインディング内でバインディングを使用することはできませんので、この方法を使用してコンバータパラメータを設定することはできません。 –

関連する問題