WPF ComboBox Text属性在更改时未更新 [英] WPF ComboBox Text property not updating when changed

查看:510
本文介绍了WPF ComboBox Text属性在更改时未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

 

大家好.我正在使用VS 2008,遇到了一些奇怪的行为,这些行为在其他形式上也可以正常使用,但是由于某种原因,这给我带来了很大的困难.

Hey all. I am using VS 2008 and am coming across some weird behaviour that works properly on other forms but for some reason is giving me great difficulty here.

 

我的表单如下: 

My form looks like this: 

 

 

底部的表单"下拉菜单旁边显示的文本只是显示第一个表单控件应该显示的文本,但显然不是.

The text that appears next to the Form drop-down at the bottom is simply showing the text that the first form control SAYS it should be showing but it obviously isn't.

 

列表中的前两个项目如下:

The first two items in the list look like this:

       

       


 <StackPanel Margin="10">

      <TextBlock FontWeight="Bold" Height="25" Text="{Trans:Translate Details}" Foreground="DarkRed"></TextBlock>

        <StackPanel>

          <StackPanel Orientation="Horizontal" Margin="0,5,0,0">

            <Label HorizontalAlignment="Left" Name="Label5" Width="150" VerticalAlignment="Top" Content="{Trans:Translate Form}"/>

            <ComboBox Name="luForms" DisplayMemberPath="English" SelectedValuePath="ID" Width="300"></ComboBox>

          </StackPanel>

          <StackPanel Orientation="Horizontal" Margin="0,5,0,0">

            <Label HorizontalAlignment="Left" Name="lblElement" Width="150" VerticalAlignment="Top" Content="{Trans:Translate Status}"/>

            <ComboBox Name="luElements" DisplayMemberPath="English" SelectedValuePath="ID" Width="300"></ComboBox>

          </StackPanel>

推荐答案

现在这是一个远景,但有时在更新ComboBox的ItemsSource已经进行数据绑定时,可能会导致此问题.只是为了好玩,请尝试调用OnPropertyChanged("Your Object")以刷新绑定.如果您不使用数据 在以MVVM方法绑定时,请尝试再次将DataContext重置为您的对象.甚至可以先将其设置为null,只是为了确保.
Now this is a long shot, but sometimes after updating a ComboBox's ItemsSource when it is already databound can cause this issue.  Just for fun, try calling the OnPropertyChanged("Your Object") to refresh the bindings.  If you are not using data binding in an MVVM approach, try resetting the DataContext to your object again.  Maybe even set it to null first, just to make sure.


这篇关于WPF ComboBox Text属性在更改时未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆