在WPF .Net 4.5应用程序中,我希望在功能区中有几个可编辑的组合框,这样我就可以在列表中选择一个值或键入一个自定义值。
将常规ComboBox
与IsEditable="True"
和IsReadOnly="False"
一起使用效果很好,但在RibbonComboBox
上设置这两个属性则不起作用:在键入值之后,当我在控件外部单击或按Enter时,键入的值将替换为以前从列表中选择的值。不会触发RibbonGallery的SelectionChanged事件。(从下拉列表中选择可以很好地工作,并正确地更新绑定的属性。)
以下是一些相关的帖子:
RibbonComboBox selected gallery item reverts to old value on mouse leave没有答案的相同问题我尝试了2d答案中的变通方法,但没有效果。即使鼠标不动,这个问题也会出现,所以这可能是无关的。
Editable ribbon combo box does not respect choices that are not in the drop-down list同样的问题,但解决方案需要创建一个自定义类来覆盖RibbonComboBox的正常行为。我还没有测试它,但对我来说,为了获得我认为的标准行为,必须这样做似乎是不正常的。
下面是一个麻烦的ribboncomboboxes的代码(Libelle是一个字符串属性,在修改时会引发一个PropertyChanged事件):
<RibbonComboBox IsEditable="True"
IsReadOnly="False"
IsTextSearchEnabled="False">
<RibbonGallery IsTextSearchEnabled="False"
SelectedValue="{Binding Libelle}" >
<RibbonGalleryCategory IsTextSearchEnabled="False">
<RibbonGalleryCategory.ItemsSource>
<x:Array Type="sys:String">
<sys:String>Zero hydro</sys:String>
<sys:String>Cote marine</sys:String>
<sys:String>Mouillage</sys:String>
<sys:String>Profondeur</sys:String>
<sys:String>Hauteur d'eau</sys:String>
</x:Array>
</RibbonGalleryCategory.ItemsSource>
</RibbonGalleryCategory>
</RibbonGallery>
我对RibbonComboBox元素不是很熟悉,所以我想知道我是否遗漏了什么明显的东西。
发布于 2015-06-08 16:35:04
是的,你错过了.这个bug ..并且不得不写它..
private void RibbonGallery_SelectionChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
Mouse.Capture(null);
}
https://stackoverflow.com/questions/30479625
复制相似问题