0

私は1つを持っていて、このようなものListboxを適用しましたDataTemplate

<ListBox>
   <ListBox.ItemTemplate>
<Grid>
 <TextBlock Text="{Binding Path=Name}" Grid.Row=0/>
    <ComoboBox Name="test"
            DisplayMemberPath="Country"
            SelectedValuePath="Country_ID">
</Grid>

  1. で選択された各項目に基づいて動的にロードItemSourceするにはどうすればよいですか? 私はWPFを初めて使用しています... plsはあなたの貴重な提案を手伝ってくれます。ComboBoxListBox
4

2 に答える 2

0

これを行う 1 つの方法は、ComboBox の ItemsSource を ListBox の SelectedValue プロパティにバインドすることです。これが機能するには、ComboBox がバインドされる項目のリストを含む項目のコレクションに ListBox をバインドする必要があります。

<ListBox
    x:Name="CategoryList"
    ItemsSource="{Binding Path=MasterList, 
        RelativeSource={RelativeSource AncestorType=Window}}"
    DisplayMemberPath="MasterProperty"
    SelectedValuePath="Details"
    />

<ComboBox
    ItemsSource="{Binding Path=SelectedValue, ElementName=CategoryList}"
    DisplayMemberPath="DetailProperty"
    Grid.Row="1"
    />

この例では、Details コレクションを含むオブジェクトのリストを公開するウィンドウのコード ビハインドでパブリック プロパティを作成しました。

public List<Master> MasterList { get; set; }

public class Master
{
    public string MasterProperty { get; set; }
    public List<Detail> Details { get; set; }
}

public class Detail
{
    public string DetailProperty { get; set; }
}
于 2009-08-01T12:15:33.560 に答える
0
<ListBox>
  <ListBox.ItemTemplate>
   <Grid>
     <TextBlock Text="{Binding Path=Name}" Grid.Row=0/>
        <ComoboBox Name="test" 
           DataContent="{Binding RelativeSource={RelativeSource AncestorType=ListBox}}"                 
           ItemsSource="{Binding}"
        DisplayMemberPath="Country"
        SelectedValuePath="Country_ID">
   </Grid>

これで、コンボボックスには常に親リストボックスと同じアイテムソースがあります。

于 2009-08-01T22:32:51.893 に答える