在ListView中的ComboBox,一行改变,其他行都变了,怎么回事?
情况是这样的:
ListView中的Type列是通过ComboBox下拉选择的,ComboBox的source是一个CollectionViewSource资源:[code=XAML]<UserControl x:Class="xxxxx.RCSZoneDesignAssist"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="400" Width="800">
<UserControl.Resources>
<CollectionViewSource x:Key="cvsTopRebar"/>
<CollectionViewSource x:Key="cvsBottomRebar"/>
</UserControl.Resources>
[/code]ComboBox以静态的方式使用CollectionViewSource:[code=XAML]<ListView Name="listViewTopRebars" Grid.Row="1" Grid.Column="0" Margin="3">
<ListView.View>
<GridView>
<GridViewColumn Header="Layer" DisplayMemberBinding="{Binding Path=Name}" HeaderTemplate="{StaticResource BlueHeader}"></GridViewColumn>
<GridViewColumn Header="Type" HeaderTemplate="{StaticResource BlueHeader}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox MinWidth="60" ItemsSource="{Binding Source={StaticResource cvsTopRebar}, Mode=OneWay}" DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding Path=Id, Mode=OneWay}" BorderThickness="1" BorderBrush="Gray"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>[/code]
问题可能出在ComboBox以静态的方式使用cvsTopRebar,所以每个ListView中的对象都使用一个CollectionViewSource对象造成的,如果一个对象的ComboBox选项改变,能让CollectionViewSource不通知其他GUI对象也好啊,可是怎么做呢?或者以动态资源的方式使用CollectionViewSource??怎么使用?
往高手出招!

解决方案 »

  1.   

    你是说多个ListView中的combobox都使用一个CollectionViewSource对象做数据源吗?
    如果这样的话,那你要给不同的combobox使用不同的数据源对象(DataTable的做法是combobox1.DataSource = dt;...combobox2.DataSource=dt.Copy();)。
      

  2.   

    <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type DockPanel}}, Path=绑定内容}" SelectedValue="{Binding Path=绑定内容}" SelectedValuePath="值 "
    <ComboBox.ItemTemplate>
        <DataTemplate>
    <TextBlock Text="{Binding Path=绑定内容}" />
        </DataTemplate>
    </ComboBox.ItemTemplate>
    </ComboBox>我试过绑定到数据库,不会出现你那样问题。希望对你有所帮助。