开发者

WPF combobox inside listview

开发者 https://www.devze.com 2023-02-03 16:17 出处:网络
I\'ve got a wpf mvvm application up and running. In one of my views I\'ve got a listbox where one column is a combobox. I thought that I had everything working, but... I ended up here.

I've got a wpf mvvm application up and running. In one of my views I've got a listbox where one column is a combobox. I thought that I had everything working, but... I ended up here.

When I select a value in the combobox in one row, all rows are changed. I've tried a lot of things and i'm stuck.

Here's my xaml:

<ListView ItemsSource="{Binding Path=Properties.OutputGroups, Mode=TwoWay}">
                <ListView.View>
                    <GridView >
                        <GridViewColumn Header="Output" >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.Outputs}" SelectedValue="{Binding Path=Obj.OutputID, Mode=TwoWay}" IsSynchronizedWithCurrentItem="False" DisplayMemberPath="DisplayName" SelectedValuePath="ID" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Duration">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding Path=Obj.Duration}" BorderThickness="0" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="State" >
     开发者_如何学编程                       <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Path=Obj.State}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>


I'm not positive about this, so I apologize if this is not correct, but according to what I have read on MSDN here, I think it might have to do with the "isSynchronizedWithCurrentItem" property. Try switching this property to "true," and see if that fixes your problem.

Like I said, I'm not positive this is where the problem is, but it seems to me like you are wanting the data to be synchronized with the current item, hence why that property is throwing up a flag to me.

I really hope this helps! (And I truly apologize if it doesn't)

0

精彩评论

暂无评论...
验证码 换一张
取 消