7

当我单击 DataGridComboBoxColumn 中的单元格时,组合框变得可见,我可以选择项目。当我选择了一个项目时,它在顶部可见。但是,当单元格又名 ComboBox 因为我单击 DataGrid 中的不同内容而失去焦点时,则在我之前选择的单元格中不再可见项目/文本。

如何保留该选择/选定的文本?

那是我的代码:

<DataGridComboBoxColumn
           Width="*"
           Header="Monday"
           DisplayMemberPath="SchoolclassName"
           SelectedValueBinding="{Binding SchoolclassCodeMonday}"  
           ItemsSource="{Binding Source={StaticResource ClassCodes}}">

    <DataGridComboBoxColumn.ElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="IsSynchronizedWithCurrentItem" Value="False" />
            <Setter Property="ItemsSource" 
                    Value="{Binding Source={StaticResource ClassCodes}}" />
        </Style>
    </DataGridComboBoxColumn.ElementStyle>

    <DataGridComboBoxColumn.EditingElementStyle>                   
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" 
                    Value="{Binding Source={StaticResource ClassCodes}}" />
            <Setter Property="IsDropDownOpen" Value="True" />
        </Style>                   
    </DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>

我的问题似乎有一个解决方案:http ://wpf.codeplex.com/Thread/View.aspx?ThreadId=46627 (滚动到底部)但我无法将解决方案转移到我的问题。因为我的模型设置完全不同。

SchoolclassName是 Schoolclass.cs 中的字符串属性 SchoolclassCodeMonday是 TimeTable.cs 中的字符串属性 ClassCodes aka SchoolclassCodes是 ObservableCollection|Schoolclass| 类型的属性

有人知道如何修复我的绑定吗?

4

1 回答 1

2

I know its probably not needed anymore but maybe it will help someone else. Would your ComboBox not need to update the binding when it's changed? e.g.

SelectedValueBinding="{Binding SchoolclassCodeMonday}"

would be:

SelectedValueBinding="{Binding SchoolclassCodeMonday, 
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  

Also make sure you are firing a notification when the property is changed from code on your observable collection.

于 2015-08-28T15:56:09.217 回答