真的没有办法在xaml绑定中跟进数据集父关系吗? [英] Is there really no way to follow up dataset parent relation in xaml binding?

查看:15
本文介绍了真的没有办法在xaml绑定中跟进数据集父关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含这两个不朽表的数据集:Employee &订购
Emp -> ID、姓名
Ord ->Something, Anotherthing, EmpID
和关系Rel:Ord (EmpID) -> Emp (ID)

Suppose I have a dataset with those two immortal tables: Employee & Order
Emp -> ID, Name
Ord -> Something, Anotherthing, EmpID
And relation Rel: Ord (EmpID) -> Emp (ID)

它在标准的主/细节场景中效果很好
(显示员工,跟进关系,显示相关订单),
但是当我不想走相反的路(用 Emp.Name 显示 Ord 表)时怎么办?

It works great in standard master/detail scenario
(show employees, follow down the relation, show related orders),
but what when I wan't to go the opposite way (show Ord table with Emp.Name)?

类似这样的:

Something like this:

<stackpanel>   // with datacontext set from code to dataset.tables["ord"]
   <TextBox Text="{Binding Something}"/>
   <TextBox Text="{Binding Anotherthing}"/>
   <TextBox Text="{Binding ???}"/> // that's my problem, how to show related Emp.Name 
</stackpanel>

有什么想法吗?我可以创建值转换器,但如果我不想使用从父模块获得的数据集实例,它会变得很棘手.

Any ideas? I can create value converter, but if I wan't to use dataset instance which I get from parent module it gets tricky.

推荐答案

如果要同步多个控件的内容,需要通过DataContext设置让它们共享同一个绑定源在一个共同的父控件上.这是一个例子:

If you want to synchronize the contents of multiple controls, you will need to have them share the same binding source through the DataContext set on a common parent control. Here is an example:

<StackPanel>
    <StackPanel.Resources>
        <ObjectDataProvider x:Key="ds" ObjectType="{x:Type mynamespace:MyDataSet}" />
    </StackPanel.Resources>

    <!-- We set the data context to the collection of rows in the table -->
    <StackPanel DataContext="{Binding Source={StaticResource ds}, Path=USERS.Rows}">
        <ListBox ItemsSource="{Binding}"
                 DisplayMemberPath="NAME"
                 IsSynchronizedWithCurrentItem="True" />
        <TextBox Text="{Binding Path=NAME}"/>
        <TextBox Text="{Binding Path=COUNTRIESRow.NAME}"/>
    </StackPanel>
</StackPanel>

IsSynchronizedWithCurrentItem 属性设置为 'True' 将导致 ListBox.SelectedItem 属性自动与 CollectionView.CurrentItem 的绑定源,即在 DataContext 处设置的行的集合.这意味着 ListBox 中当前选定的行成为两个 TextBox 控件的绑定源.

Setting the IsSynchronizedWithCurrentItem property to 'True' will cause the ListBox.SelectedItem property to be automatically synchronized with the CollectionView.CurrentItem of the binding source, that is the collection of rows set at the DataContext. This means that the currently selected row in the ListBox becomes the binding source for the two TextBox controls.

这篇关于真的没有办法在xaml绑定中跟进数据集父关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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