[英]DataGridComboBoxColumn loses its content when selection changes
When I click a cell in my DataGridComboBoxColumn the ComboBox gets visible and I can select items. 当我单击DataGridComboBoxColumn中的单元格时,ComboBox变为可见,我可以选择项目。 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.
但是当单元格ComboBox失去焦点时,因为我在DataGrid中点击了不同的东西,所以在我之前选择的单元格中没有可见的项目/文本。
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. 似乎有一个解决我的问题的方法: http : //wpf.codeplex.com/Thread/View.aspx? ThreadId = 46627 (滚动到底部)但我无法将解决方案转移到我的问题。 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| SchoolclassName是Schoolclass.cs中的字符串属性SchoolclassCodeMonday是TimeTable.cs中的字符串属性ClassCodes又名SchoolclassCodes是ObservableCollection类型的属性| Schoolclass |
Someone knows how to fix my binding? 有人知道如何修复我的绑定?
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?
您的ComboBox在更改时不需要更新绑定吗? eg
例如
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. 还要确保在从可观察集合上的代码更改属性时触发通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.