プロパティObservableCollection<ObservableCollection<Location>>
をListBoxのItemTemplateを持つListBoxにバインドしようとしていますが、ListBoxのItemTemplateにはグリッドのItemTemplateがあります。リストボックス内のリストボックスのレイアウトはうまくいくようです。しかし、私はデータバインディングに問題があります。コレクションのコレクションにバインドされたリストボックスのリストボックス
2番目のレイヤーリストボックスのItemsSource私は、Collection Current Item Bindings ItemSource="{Binding /}"
を使用し、ItemsSource="{TemplateBinding /}"
を使用してバインディングを試行しました。私はWPFを初めて使い、MVVMを使っていますので、ヒントや批評をいただければ幸いです。
<ListBox Grid.Row="4" Width="610" Height="600" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentLocation.Children}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox Width="550" Height="100" Margin="5" HorizontalContentAlignment="Stretch" ItemsSource="{Binding /}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Margin="5" Text="Name:" />
<TextBlock Grid.Column="0" Grid.Row="1" Margin="5" Text="Description:" />
<TextBlock Grid.Column="1" Grid.Row="0" Margin="5" Text="{Binding Name}" />
<TextBlock Grid.Column="1" Grid.Row="1" Margin="5" Text="{Binding Description}" TextWrapping="Wrap" />
<Button Grid.Column="2" Grid.Row="0" Command="{Binding TODO}">
<TextBlock Text="Edit"/>
</Button>
<Button Grid.Column="2" Grid.Row="1" Command="{Binding TODO}">
<TextBlock Text="Delete"/>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
なぜリストボックスを含むリストボックスが必要ですか? – Bernard