Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 组合框的selectionchanged中显示数据不正确_C#_Wpf_Xaml - Fatal编程技术网

C# 组合框的selectionchanged中显示数据不正确

C# 组合框的selectionchanged中显示数据不正确,c#,wpf,xaml,C#,Wpf,Xaml,在XAML中: <Grid Background="White"> <ComboBox Grid.Row="0" x:Name="BackTagBox" ItemsSource="{Binding DataContext, RelativeSource={RelativeSource Self}}" Displa

在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>
如果我在ddl中选择“秒”和“下一项”,则数据不会显示,尽管它正确地添加到了
Item.Sides


仅当我选择第一项时才会显示数据

将属性侧的类型更改为
可观察收集
,而不是
列表

此类型将向您保证,对集合的更改将自动通知给UI,以便应用更改

您的数据类缺少一些信息,所以我只能猜测。 您说过,只有在选择第一项时,它才起作用:


-->列表“Sides”最初是由第一项的数据填充的,还是由事件填充的?

Sides是可观察的CollectionList“Sides”是由第一项和第二项的数据初始化的,但不显示第二项的数据。您可以发布其余的代码吗?,就目前的例子而言,很难找到问题所在。
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);
            }

        }