Can't apply itemssource to StackPanel

<ItemsControl x:Name="tabControlpanelN" ItemsSource="{Binding obListN}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel IsItemsHost="True"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderThickness="1" Margin="2" CornerRadius="4"> <StackPanel> <TextBlock Text="{Binding fullName}" FontWeight="Bold"/> <TextBlock Text="{Binding bdate}"/> <TextBlock Text="{Binding adress}"/> <TextBlock Text="{Binding period}"/> </StackPanel> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 

ObservableCollection is filled in the code from the base.

 ObservableCollection<BaseRowItem> obListN=new ObservableCollection<BaseRowItem>(); while (dr.Read()){ obListN.Add(new BaseRowItem(){ fullName =dr["name1"].ToString() + " " + dr["name2"].ToString() + " " + dr["name3"].ToString(), bdate = "Дата рожд. " + dr["birthdate"].ToString(), adress = "Адрес " + dr["adress"].ToString(), period = "Период " + dr["date_in"].ToString() + "-" + dr["date_out"].ToString(), }) } tabControlpanelN.DataContext = obListN; 

StackPanel is empty

  • one
    tabControlpanelN.DataContext = obListN; - here is an error, you set obListN as a context, then the binding looks for the obListN property in this object, which, of course, is not there. Or write tabControlpanelN.ItemsSource = obListN; , or ItemsSource="{Binding}" . - Andrey NOP

0