私はoptions
とitems
の2つのテーブルを持っています。 1つの項目は複数のオプションに関連付けられています。WPFで関連するテーブルをバインドする方法は?
は、私は、ネストされたListBox
s内の項目とそのオプションを表示します。問題は、内部のListBox
は物を表示しないということです。私はたぶんItemsSource
を正しく束縛しなかったと思います。どのようにそれをバインドするには?以下
私の試み:アイテムの
<Window.Resources>
<local:TaxAccessmentDataSet x:Key="taxAccessmentDataSet"/>
<CollectionViewSource x:Key="itemsViewSource" Source="{Binding items, Source={StaticResource taxAccessmentDataSet}}"/>
<CollectionViewSource x:Key="itemsoptionsViewSource" Source="{Binding FK_options_items, Source={StaticResource itemsViewSource}}"/>
</Window.Resources>
<ListBox x:Name="listBox"ItemsSource="{Binding}" DataContext="{StaticResource itemsViewSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<Expander x:Name="expander" Header="{Binding name}">
<ListBox ItemsSource="{Binding}" DataContext="{StaticResource itemsoptionsViewSource}" DisplayMemberPath="name">
</ListBox>
</Expander>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
私はこれを試して、それは動作しませんでした。 'childView'は空で、' optionsDataTable'である 'childView.Table'も空です。しかし、私の 'options'テーブルにはデータがあります。 –
データの関係がどのように設定されているかを説明する(投稿する)必要があります。もちろん、これを有効にするには、テーブル間に有効な関係を設定する必要があります。 MSDNの例を確認してください:https://msdn.microsoft.com/en-us/library/system.data.datatable.childrelations(v=vs.110).aspx – mm8
私は 'optionsTableAdapter'を' 'options'テーブルをFill()します。今はデータがありますが、 'childView'はまだ空です。 –