2009-03-25 1 views
0

私はWPFの初心者ですので、愚かな質問は残念です。WPF:TreeviewItemのコンボボックス

コンボボックスを選択したTreeViewItemと並べて表示することはできますか? http://www.mypicx.com/03242009/Combobox_in_TreeviewItem/

は、私はこのように実行しようとしました:

は、私は次のリンクで、左の写真に示すようなものを必要とする

<TreeView Name="treeView1">
<TreeViewItem Header="aaa">
<ComboBox Height="19">
<ComboBoxItem Content="111" IsSelected="True"></ComboBoxItem>
<ComboBoxItem>222</ComboBoxItem>
<ComboBoxItem Content="333"></ComboBoxItem>
</ComboBox>
<TreeViewItem Header="aaa1">
</TreeViewItem>
<TreeViewItem Header="aaa2">
</TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="bbb">
<TreeViewItem Header="bbb1" />
<TreeViewItem Header="bbb2" />
</TreeViewItem>
<TreeViewItem Header="ccc" />
</TreeView>

、あなたは右の画像に表示することができた結果。

私はこれを視覚的に行う方法を知る必要があります。後でSelectedItemChangedイベントで何かする必要があります。

ありがとうございます!

P.S.あなたがする必要がどのような私の英語

答えて

3

について申し訳ありませんが、そのような

<TreeView Name="treeView1"> 
    <TreeViewItem> 
     <TreViewItem.Header> 
      <StackPanel Orientation="Horizontal"> 
       <ComboBox Height="19"> 
        <ComboBoxItem Content="111" IsSelected="True"></ComboBoxItem> 
        <ComboBoxItem>222</ComboBoxItem> 
        <ComboBoxItem Content="333"></ComboBoxItem> 
       </ComboBox> 
      </StackPanel> 
     </TreViewItem.Header> 
     <TreeViewItem Header="aaa1"> 
     </TreeViewItem> 
     <TreeViewItem Header="aaa2"> 
     </TreeViewItem> 
    </TreeViewItem> 
    <TreeViewItem Header="bbb"> 
     <TreeViewItem Header="bbb1" /> 
     <TreeViewItem Header="bbb2" /> 
    </TreeViewItem> 
    <TreeViewItem Header="ccc" /> 
</TreeView> 
0

ありがとうございました。 すでに数日かかるので、コンボボックスは選択したノードの隣にのみ表示されます。 私はツリービューを単純なXMLデータファイルにバインドし、スタイルを通してコンボボックスを表示しようとしました。 ?


< XMLバージョン= "1.0" エンコード= "UTF-8": は、ここに私のXMLデータのですか? >
<ルート名= "ルート" >
<ノード名= "AAA" >
<子ノード名= "AAA 1"/>
<子ノード名= "AAA 2"/>
<子ノード名= "AAA 3"/>
< /ノード>
<ノード名= "BBB" >

:子ノード名= "BBB 1"/>
<子ノード名= "BBB 2"/>
< /ノード>
< /ルート>


そして、ここでは私の弱い試みです
<HierarchicalDataTemplate DataType="Node" ItemsSource="{Binding XPath=*}" x:Key="normal"> 
     <TextBlock Text="{Binding [email protected]}"/> 
    </HierarchicalDataTemplate> 
    <HierarchicalDataTemplate DataType="Node" ItemsSource="{Binding XPath=*}" x:Key="selected"> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock Text="{Binding [email protected]}"/> 
      <ComboBox> 
       <ComboBoxItem IsSelected="True">111</ComboBoxItem> 
       <ComboBoxItem>222</ComboBoxItem> 
       <ComboBoxItem>333</ComboBoxItem> 
      </ComboBox> 
     </StackPanel> 
    </HierarchicalDataTemplate> 

    <DataTemplate x:Key="normal1" DataType="ChildNode"> 
     <TextBlock Text="{Binding [email protected]}"/> 
    </DataTemplate> 
    <DataTemplate x:Key="selected1" DataType="ChildNode"> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock Text="{Binding [email protected]}"/> 
      <ComboBox> 
       <ComboBoxItem IsSelected="True">111</ComboBoxItem> 
       <ComboBoxItem>222</ComboBoxItem> 
       <ComboBoxItem>333</ComboBoxItem> 
      </ComboBox> 
     </StackPanel> 
    </DataTemplate> 

    <Style TargetType="{x:Type TreeViewItem}" x:Key="ContainerStyle"> 
     <Setter Property="HeaderTemplate" Value="{StaticResource normal}" /> 
     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="True"> 
       <Setter Property="HeaderTemplate" Value="{StaticResource selected}" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 

    <XmlDataProvider x:Key="XmlNodeList" Source="XMLFile1.xml"/> 

</Window.Resources> 

<Grid> 
    <TreeView ItemContainerStyle="{StaticResource ContainerStyle}"> 
     <TreeViewItem Header="{Binding Source={StaticResource XmlNodeList}, XPath=/Root/@Name}" 
         ItemsSource="{Binding Source={StaticResource XmlNodeList}, XPath=/Root/Node}" /> 
    </TreeView> 
</Grid> 

このコードはコンパイルをパスしますが、実行時に例外をスローします。アイテムはすでに追加されています。キーの辞書: 'DataTemplateKey(Node)'キーが追加されました: 'DataTemplateKey(Node)'

私の方法は間違っていますが、解決策は何ですか?