多个数据绑定的问题 (Silverlight)
我正在使用 silverlight 创建一个 Intranet 来管理化学品的使用。所有数据都存储在 MS SQL 数据库中,并使用 DomainService (RIA) 进行检索。
通过将数据库拖到表单上,Silverlight 就基于该表创建了一个 DomainDataSource。然后使用以下代码创建新记录,我现在可以添加新记录。
Me.ChemicalApplicationDomainDataSource.DataView.Add(chemicalApplication)
然而,我在屏幕上的控件之一是 AutoCompleteBox。我已将其绑定到数据库,并且这些值在此处显示良好。当在这里选择一个项目时,我想用从第二个数据表检索的值填充文本框的值。
我在 AutoSelectedItemChanged 上创建了一个事件,并添加了以下代码:
Context.Load(Context.GetChemicalByNameQuery(AutoMaterialTradeName.Text))
然后我可以将其绑定到 datagrid.ItemsSource,它会显示相关记录。但我一生都无法将其绑定到文本框。文本框没有 ItemsSource,只有 DataContext,但绑定到此似乎没有显示任何内容。
有关如何实现此目的有任何提示吗?
I am using silverlight to create an Intranet for managing chemical usage. All data is stored in a MS SQL database, and is retrieved by using a DomainService (RIA).
By dragging the database onto the form, Silverlight has created a DomainDataSource based on this table. By then creating a new record using the following code, I am now able to add new records.
Me.ChemicalApplicationDomainDataSource.DataView.Add(chemicalApplication)
However one of the controls I have on the screen is an AutoCompleteBox. I have bound this to the database, and the values display fine on here. When an item is selected on here, I want to populate the value of a textbox with values retrieved from a second datatable.
I have created an event on the AutoSelectedItemChanged, and added the following code:
Context.Load(Context.GetChemicalByNameQuery(AutoMaterialTradeName.Text))
I can then bind this to a datagrid.ItemsSource, and it shows the relevent record. But I cannot for the life of me get it to bind to a textbox. Textboxes dont have an ItemsSource, only a DataContext, but binding to this does not seem to display anything..
Any tips on how to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将其绑定到 TextBox 上的 Text 属性才能正常工作。此外,您可能需要在绑定上设置 Path 属性才能在对象上显示正确的属性。
You would need to bind it to the Text property on the TextBox for that to work. Additionally you would probably need to set the Path property on the binding to get the right property on your object to display.