I my XAML, I have a ListBox defined
<ListBox x:Name="lstStatus" Height="500"
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Top" Margin="2, 2, 2, 2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image />
<TextBlock Width="70" Text="{Binding FriendlyID}" />
<TextBlock Width="150" Text="{Binding StatusName}" />
<TextBlock Width="70" Text="{Binding ANI}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Effect>
<DropShadowEffect/>
</ListBox.Effect>
</ListBox>
In the code-behind, I define a module-level ObservableCollection devices.
private ObservableCollection<Device> devices = new ObservableCollection<Device>();
In the OnNavigatedTo event I bind the collection to the listbox
lstStatus.ItemsSource = devices;
The collection will most likely not grow or shrink but the objects within themselves change all the time. For whatever reason, the list does not get updated, when I execute the following code:
Device selectedDevice = null;
foreach (Device dv in devices)
{
if (dv.IsTrunk)
{
selectedDevice = dv;
break;
}
}
if (selectedDevice != null)
selectedDevice.StatusName = DateTime.Now.ToString();
else
throw new Exception();
In fact, the only way I was able to halfway get it to work is to fake it out, remove items from the list and then add it back up. Obviously not a solution for the long term.
What am I missing?