WPF:自动完成框选定项
我有一个对象绑定到窗口中的控件。该对象有一个名为“Region”的属性,以及一个填充了可用“Regions”列表的 ObjectDataProvider。我正在使用 WPF 工具包 AutoCompleteBox 来选择所选区域,但所选值不会更新以反映对象的区域。例如:如果我使用下面的代码,我可以打开/保存表单,并且 AutoCompleteBox 显示为空白,即使该区域已保存(因此它必须绑定,但不可见?)
<input:AutoCompleteBox x:Name="txtRegionAuto" Grid.Row="0" Grid.Column="1"
IsTextCompletionEnabled="False" ValueMemberPath="Region" ItemTemplate="{StaticResource RegionDataTemplate}" Margin="2,4" Style="{StaticResource AutoCompleteComboBoxStyle}" TabIndex="8" SelectedItem="{Binding Region,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="lstRegion_SelectionChanged"
ItemsSource="{Binding Source={StaticResource regionProvider}}" MinimumPopulateDelay="400" />
我可以让该区域显示的唯一方法该框是:
txtRegionAuto.SelectedItem = regions.FirstOrDefault(c => c.RegionID == region.RegionID);
但是当我保存表单时,我的对象上的 Region 属性为空。我确信这只是设置正确的值绑定的情况,但我不确定要使用什么。
I have an object bound to controls in a window. There's a property on this object called "Region", and an ObjectDataProvider which is populated with a list of available "Regions". I'm using a WPF toolkit AutoCompleteBox to select the region selected but the value selected isn't update to reflect the region of the object. Eg: If I use the code below, I can open/save the form and the AutoCompleteBox appears blank, even though the region is saved (so it must be bound, but invisible?)
<input:AutoCompleteBox x:Name="txtRegionAuto" Grid.Row="0" Grid.Column="1"
IsTextCompletionEnabled="False" ValueMemberPath="Region" ItemTemplate="{StaticResource RegionDataTemplate}" Margin="2,4" Style="{StaticResource AutoCompleteComboBoxStyle}" TabIndex="8" SelectedItem="{Binding Region,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="lstRegion_SelectionChanged"
ItemsSource="{Binding Source={StaticResource regionProvider}}" MinimumPopulateDelay="400" />
The only way I can get the region to display in the box is with:
txtRegionAuto.SelectedItem = regions.FirstOrDefault(c => c.RegionID == region.RegionID);
But then when I come to save the form, the Region property on my object is null. I'm sure it's just a case of setting the right value binding, but I'm not sure what to use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您遇到了一个错误:https: //connect.microsoft.com/VisualStudio/feedback/details/595640/autocompletebox-does-not-update-visible-text
i guess you encountered a bug: https://connect.microsoft.com/VisualStudio/feedback/details/595640/autocompletebox-does-not-update-visible-text