2011-07-28 3 views
-1

コンボボックス内の選択された文字列値に基づいて、グリッド内に赤色/青色のデータ文字列を表示します。コンボボックスの選択された文字列値に応じてデータテンプレートを切り替えます

これはContentControlなしで行うことができますか?

<UserControl.Resources > 

<DataTemplate x:Key="red"> 
     <TextBox Text="red" /> 
    </DataTemplate> 

    <DataTemplate x:Key="blue"> 
     <TextBox Text="blue" /> 
    </DataTemplate> 

</UserControl.Resources> 

<ComboBox ??? /> 
<Grid> 
    // Show red or blue datatemplate here 
</Grid> 
+0

なぜ「コンテンツコントロールなし」:

は単に私はコンボボックスは、その後に結合することができ、アレイ内のテンプレートを、置くこの作業を行うには? –

答えて

0

なぜContentControlを使用しないのですか?

<x:Array x:Key="templates" Type="{x:Type DataTemplate}"> 
    <DataTemplate> 
     <DataTemplate.Resources> 
      <sys:String x:Key="DisplayString">Red</sys:String> 
     </DataTemplate.Resources> 
     <TextBox Text="red" /> 
    </DataTemplate> 

    <DataTemplate> 
     <DataTemplate.Resources> 
      <sys:String x:Key="DisplayString">Blue</sys:String> 
     </DataTemplate.Resources> 
     <TextBox Text="blue" /> 
    </DataTemplate> 
</x:Array> 
<ComboBox Name="combo" ItemsSource="{StaticResource templates}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding Resources[DisplayString]}" /> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 
<Grid> 
    <ContentControl ContentTemplate="{Binding SelectedItem, ElementName=combo}" /> 
</Grid> 
+0

私は私のviewmodelのニーズに合わせてソリューションを調整しました:) – Elisabeth

関連する問題