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

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

问题描述

假设我有一个数据集与这两个不朽的表:员工&订单
Emp - > ID,名称
Ord - > Something,Anotherthing,EmpID

和关系 Rel :Ord(EmpID) - > Emp(ID)



它在标准主/详细情况a
(显示员工,跟随关系,显示相关的订单),

但是当我不会相反的方式(显示Ord表与Emp 。名称)?



这样的人物:

 < stackpanel> // with datacontext set from code to dataset.tables [ord] 
< TextBox Text ={Binding Something}/>
< TextBox Text ={Binding Anotherthing}/>
< TextBox Text ={Binding ???}/> //这是我的问题,如何显示相关的Emp.Name
< / stackpanel>

任何想法?我可以创建价值转换器,但是如果我不使用从父模块获取的数据集实例,那么它会变得棘手。

解决方案

如果要同步多个控件的内容,则需要通过在一个公共父控件上设置的 DataContext 来共享相同的绑定源。这是一个例子:

 < StackPanel> 
< StackPanel.Resources>
< ObjectDataProvider x:Key =dsObjectType ={x:键入mynamespace:MyDataSet}/>
< /StackPanel.Resources>

<! - 我们将数据上下文设置为表中的行集合 - >
< 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控件的绑定源。


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)

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.

解决方案

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>

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天全站免登陆