I have an observable collection which is being populated from a networking thread. If a populate the OC from the constructor with dummy data it shows up on the UI. I know that the items are being added to the collection from the network thread but the Items count never updates on the UI.
My view model is as follows:
public class ManikinStatusViewModel : DiViewModelBase
{
private readonly ICommunicationService manikinCommunicationService;
#region Properties
public ObservableCollection<CasualtyStatusViewModel> Manikins { get; private set; }
#endregion
public ManikinStatusViewModel()
{
Manikins = new ObservableCollection<CasualtyStatusViewModel>();
uow = UnitOfWorkFactory.Instance.CreateRunScenarioUnitOfWork(false);
AccelermeterPacketData apd = new AccelermeterPacketData(56, 57, 58);
manikinCommunicationService = new TestingCommunicationService(LoadAnalogSensorData(), apd);
manikinCommunicationService.ManikinDataReceived += ManikinCommunicationService_ManikinDataReceived;
}
#region Events
private void ManikinCommunicationService_ManikinDataReceived(object sender, ManikinDataReceivedEventArgs e)
{
if (e.ManiknDataPacket != null)
{
var manikin = Manikins.ToList().Find(m => m.ManikinId == e.ManiknDataPacket.SerialNumber);
if (manikin == null)
{
Debug.WriteLine("Creating manikin with serial number: " + e.ManiknDataPacket.SerialNumber);
CasualtyStatusViewModel csvm = new CasualtyStatusViewModel(e.ManiknDataPacket.SerialNumber);
Manikins.Add(csvm);
manikin = csvm;
Debug.WriteLine("manikin count is: " + Manikins.Count());
}
manikin.UpdateManikinStatus(e.ManiknDataPacket);
}
}
#endregion
I am binding the manikins collection to the following view.
<TabControl Grid.Row="1" ItemsSource="{Binding Manikins}" Name="ManikinsTabControl">
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="Header" Value="Casualty"></Setter>
<Setter Property="ContentTemplate" Value="{StaticResource CasualtyTemplate}"></Setter>
</Style>
</TabControl.Resources>
</TabControl>