在Silverlight窗口中设置ComboBox选定值 [英] Set ComboBox Selected Value in Silverlight Window

查看:130
本文介绍了在Silverlight窗口中设置ComboBox选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Silverlight窗口,其中包含带有其他字段集的ComboBox.
我从Silverlight页面设置了窗口的DataContext.
除组合框列外,所有字段均已正确映射.
它始终显示ComboBox中的First项目,而不显示SelectedItem.
我试图将ComboBox selectedvalue设置为选定的项目,但似乎没有任何效果.

以下是我编写的代码.

Hi,

I have a Silverlight Window which has a ComboBox with a set of other fields.
I set the DataContext of the Window from the Silverlight Page.
all the Fields are mapped correctly, except for the ComboBox Column.
It always displays the First item in the ComboBox and not the SelectedItem.
I tried to set the ComboBox selectedvalue selected item and nothing seem to work.

Following is the code that i have written.

<ComboBox Name="cmbCodeParts"

     Width="120"

     HorizontalAlignment="Left"

     ItemsSource="{Binding ElementName=tblRecipe_CodePartsTypeDomainDataSource, Path=Data}"

     DisplayMemberPath="codePartsType"

     SelectedValuePath="codePartsTypeID"

     SelectedValue="{Binding codePartsTypeID,Mode=TwoWay}"/>



我已经在数据表单内容加载事件中为组合框加载了DomainDataSource.

有人对此有很好的样本吗?我将不胜感激帮助纠正我的代码中的所有错误.



I have loaded the DomainDataSource for the combobox in the dataform content loaded event.

Does anybody have a good working sample of this? I would appreciate help correcting my code for any errors.

推荐答案

Learning_abc写道:
Learning_abc wrote:

SelectedValue ="{Binding codePartsTypeID,Mode = TwoWay}"/>

SelectedValue="{Binding codePartsTypeID,Mode=TwoWay}"/>



它是不是您的DataContext具有codePartsTypeID作为属性?

您可以添加一些调试转换器以检查是否获得了值(非null).您还必须检查输出窗口",因为所有绑定错误都将丢到那里.

对于调试数据绑定,您可以阅读 XAML DataBinding中的调试技巧 [ ^ ]

如果有帮助,请将其标记为答案



Does it your DataContext has codePartsTypeID as property?

You can add some debug converters to check it you get value (other than null). You have to check your Output Window too as all the Binding Errors are thrown there.

For Debugging DataBinding, you can read Debugging Trick in XAML DataBinding[^]

Mark it as answer if it is helpful


您好,Venkatesh Mookkan,

是的,DataContext具有codePartsTypeID属性.
我添加了Converter,但没有收到错误消息.
我不明白怎么了?
Hi Venkatesh Mookkan,

Yes the DataContext has the codePartsTypeID property.
I added the Converter and i get no error message.
I don''t understand what is wrong?


这篇关于在Silverlight窗口中设置ComboBox选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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