2016-08-28 37 views
0

我想要一个组合框,其ItemsSource是从posteViewSource提供的,它的SelectedItem被绑定到链接到superviseurViewSource的表的idPoste字段。如何绑定到不同来源的两个属性?

<Window.Resources> 
    <local:StagesBDDataSet x:Key="stagesBDDataSet"/> 
    <CollectionViewSource x:Key="superviseurViewSource" Source="{Binding Superviseur, Source={StaticResource stagesBDDataSet}}"/> 
    <CollectionViewSource x:Key="posteViewSource" Source="{Binding Poste, Source={StaticResource stagesBDDataSet}}"/> 
</Window.Resources> 

这里是我的组合框的定义:

 <ComboBox x:Name="idPosteComboBox" DataContext="{StaticResource posteViewSource}" ItemsSource="{Binding}" Height="23" Width="120" DisplayMemberPath="idPoste" /> 

组合框在网格中,其DataContext设置:{StaticResource的superviseurViewSource}。与项目的绑定完美的工作,但我不知道是否有可能有SelectedItem属性的另一个DataContext。任何提示将不胜感激,谢谢。

+0

不有道理,结合'SelectedItem'到项目的'idPoste' - >是的,它结合一个'CollectionViewSource' - >否,这个集合中的哪个项目会被绑定到? – Aybe

+0

这也是idPoste。组合框填充Poste表的行(链接到上面提到的collectionviewsource),工作正常。现在我想要的是将该组合框中的selecteditem与Superviseur表的collectionviewsource的当前行中的字段idPoste绑定。解释它有点难度,我希望这会有所帮助。 – snoreau

+0

那么你必须跟踪当前在这个表中选择的项目,你可能正在使用数据网格或其他东西:http://stackoverflow.com/a/13755582/361899。一旦你有了,你可以绑定到某个控件的其他地方的属性,比如'' – Aybe

回答

0

你可以有一个的ItemSource绑定和其他的SelectedItem绑定,所以你可以写:

<ComboBox x:Name="idPosteComboBox" 
    DataContext="{StaticResource posteViewSource}" ItemsSource="{Binding}" 
    SelectedItem="{Binding ---another binding---}" 
    IsSynchronizedWithCurrentItem="True" 
    Height="23" Width="120" DisplayMemberPath="idPoste" /> 
+0

谢谢你的时间。我试过了,但没有运气。这可以用于SelectedItem的绑定吗? SelectedItem =“{Binding Source = superviseurViewSource,Path = idPoste,Mode = TwoWay}” – snoreau

相关问题