media media - 1 year ago 61
C# Question

ItemControl does not work

I have the following


<ScrollViewer BorderThickness="1" Margin="5">
<Button HorizontalAlignment="Center" Content="Show History"
Margin="10" Name="btnShowHistory" Click="btnShowHistory_Click" />
<ItemsControl Name="itemControl">
<StackPanel Margin="2">
<telerik:RadExpander Header="{Binding Header}"
Content="{Binding Content}" />

And the following code behind:

private void btnShowHistory_Click(object sender, RoutedEventArgs e)
List<HistoryClass> res =;

foreach (var item in res)
StackPanel oStackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
oStackPanel.Children.Add(new TextBlock()
Foreground = Brushes.DarkBlue,
Text = item.word.ToString(),
Margin = new Thickness(10)
StackPanel oContent = new StackPanel();
foreach (var innerItem in item.meaning)
oContent.Children.Add(new TextBlock()
Foreground = Brushes.MediumPurple,
Text = innerItem.ToString(),
Margin = new Thickness(20, 10, 10, 10)

list.Add(new RadExpander() { Header = oStackPanel, Content = oContent });

this.itemControl.ItemsSource = list;

During the life cycle of my program
changes the value of
. I do not know why the
does not update. I am working on this more than usual and can't figure out the reason. Thanks for helps.

Answer Source

in the beginning of the C# function after the first instruction type the following code:
this.list = new List<RadExpander>();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download