选择更改时 DataGridComboBoxColumn 会丢失其内容
当我单击 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 又名 SchoolclassCodes 是 ObservableCollection|Schoolclass| 类型的属性
有人知道如何修复我的绑定吗?
When I click a cell in my DataGridComboBoxColumn the ComboBox gets visible and I can select items. When I have selected an item its visible at the top thats fine. But when the cell aka ComboBox loses its focus because I click something different in the DataGrid then there is no item/text visible anymore in the cell I have previously selected.
How can I keep that selection/selected text?
thats my code:
<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>
there seems to be a solution for my problem: http://wpf.codeplex.com/Thread/View.aspx?ThreadId=46627 (scroll to the bottom) but I can not transfer the solution to my problem. Because my model setup is quite different.
SchoolclassName is a string property in Schoolclass.cs
SchoolclassCodeMonday is a string property in TimeTable.cs
ClassCodes aka SchoolclassCodes is a property of type ObservableCollection|Schoolclass|
Someone knows how to fix my binding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道它可能不再需要了,但也许它会帮助其他人。
您的 ComboBox 在更改时不需要更新绑定吗?例如
:
还要确保当可观察集合上的代码更改属性时,您会触发通知。
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.
would be:
Also make sure you are firing a notification when the property is changed from code on your observable collection.