在XAML中:
<Grid Background="White">
<ComboBox Grid.Row="0"
x:Name="BackTagBox"
ItemsSource="{Binding DataContext, RelativeSource={RelativeSource Self}}"
DisplayMemberPath="Name"
SelectedValuePath="Id"
SelectionChanged="SelectionChanged" Margin="88,0,555,0"/>
<ListView ItemsSource="{Binding Sides}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Width="225px" Height="250px">
<StackPanel Name="Side" Width="225px" Height="250px">
<TextBlock Name="Name" Text="{Binding Path=Name}">
</TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
在守则背后:
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var List = (ComboBox)sender;
var Item = (LabelBagItem)List.SelectedItem;
if (selectedItem == null)
return;
foreach (var side in GetSides(Item.Id, Item.number))
{
Item.Sides.Add(sideWeight);
}
}
如果我选择ddl第二个和下一个项目,那么在正确添加Item.Sides
的情况下数据不会显示。
数据仅在我选择第一项时显示