我真的快疯了。我有一个很好的组合框,里面填满了我的CallsItems...绑定非常好,但是在代码后端设置Combobox.SelectedIndex = "0"
之后,显示第一个条目时出错。(组合框选项字段保持为空)
My Xaml of the Combobox
<PivotItem> <PivotItem.Header> <TextBlock x:Uid="section1"/> </PivotItem.Header> <Grid Grid.Row="1"> <ComboBox x:Name="cb_arbeitsplatz" x:Uid="arbeitsplatz" Header="Wähle Arbeitsplatz" ItemsSource="{Binding}" Margin="0,6,0,0" SelectionChanged="cb_arbeitsplatz_SelectionChanged" > <ComboBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding BEZEICH}" Style="{StaticResource HeaderTextStyle}"/> <TextBlock Text="{Binding ARBPLATZ}"/> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> </Grid> </PivotItem>
That's my code
public ObservableCollection<arbeitsplatz_class> cb_viewmodel = new ObservableCollection<arbeitsplatz_class>(); public _04_request() { DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait | DisplayOrientations.Landscape; this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += this.NavigationHelper_LoadState; this.navigationHelper.SaveState += this.NavigationHelper_SaveState; } public NavigationHelper NavigationHelper { get { return this.navigationHelper; } } private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { await JSON_arbeitsplatz.get_JSON("", cb_viewmodel); cb_arbeitsplatz.DataContext = cb_viewmodel; cb_arbeitsplatz.SelectedIndex = 0; ... }
This is the error I get from VisualStudio. And it's only for the first Item. All the Rest works pretty fine:
Error: BindingExpression path error: 'BEZEICH' property not found on 'System.Collections.ObjectModel.ObservableCollection`1[[GANTERportal.Data.arbeitsplatz_class, GANTERportal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. BindingExpression: Path='BEZEICH' DataItem='System.Collections.ObjectModel.ObservableCollection`1[[GANTERportal.Data.arbeitsplatz_class, GANTERportal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Text' (type 'String') Error: BindingExpression path error: 'ARBPLATZ' property not found on 'System.Collections.ObjectModel.ObservableCollection`1[[GANTERportal.Data.arbeitsplatz_class, GANTERportal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. BindingExpression: Path='ARBPLATZ' DataItem='System.Collections.ObjectModel.ObservableCollection`1[[GANTERportal.Data.arbeitsplatz_class, GANTERportal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Text' (type 'String')
I can pick the first item. It's shwoing when I'm clicking on the Combobox Unfortunately I can't send pictures
But choosing the first item will lead to a blank Combobox, due to binding Errors. Again that's only when I'm Setting the Selection of the Combobox from code behind...???? Unfortunately I can't send pictures