我有ComboBox,其中我從我的「設置」對象與UserTypes ObservableCollection裏面我的ItemsSource,我需要將其SelectedItem綁定到我的「Employee」對象的類型屬性。窗口中還有其他字段,它們正確地綁定到「Employee」對象中的其他屬性,ItemsSource在Settings中正確填充了UserTypes屬性,唯一不起作用的是不與Combo綁定的type屬性'x selecteditem,可能是因爲它的datacontext被設置爲「Settings」對象。以下是我迄今爲止:ComboBox ItemsSource從SelectedItem中有不同的datacontext
<CollectionViewSource x:Key="settingsViewSource" d:DesignSource="{d:DesignInstance my:Settings, CreateList=True}" />
<CollectionViewSource x:Key="settingsUserTypesViewSource" Source="{Binding Path=UserTypes, Source={StaticResource settingsViewSource}}" />
<ComboBox DataContext="{StaticResource settingsUserTypesViewSource}" Name="userTypeBox" VerticalAlignment="Top" Width="100" Margin="2" ItemsSource="{Binding}"
SelectedItem="{Binding Path=Type, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
在後面的代碼,我有:
InitializeComponent();
this.emp = emp;
InfoTab.DataContext = emp;
userTypeBox.DataContext = MainWindow.ViewSettings.UserTypes;
EMP是綁定到正確的領域特定員工,只有組合框將selectedItem不工作。任何幫助將不勝感激。
只是一個想法.. 。你的對象是否有「Type」屬性?嘗試更改該名稱,因爲已經存在「System.Type」。 – NestorArturo 2012-07-18 20:57:50
,根本沒有幫助,沒有問題之前 – Erika 2012-07-18 21:10:38
請發佈您的對應的ViewModel代碼,其中有界的屬性駐留... – 2012-07-18 21:26:47