I have a bear of time figuring out how to handle Thread from a class outside my ViewModel.
A topic comes from a class Track. Here is the code ResponseEventHandlerin Track:
public delegate void ResponseEventHandler(AbstractResponse response);
public event ResponseEventHandler OnResponseEvent;
When the command method is processed from my object Track, the following code runs OnResponseEvent, which sends a message to Thread back to my ViewModel:
if (OnResponseEvent != null)
{
OnResponseEvent(GetResponseFromCurrentBuffer());
}
GetResponseFromCurrentBuffer()just returns the message type, which is the predefined type in Track.
My constructor MainWindowViewModelcreates an event handler for OnResponseEventfrom Track:
public MainWindowViewModel()
{
Track _Track = new Track();
_Track.OnResponseEvent +=
new Track.ResponseEventHandler(UpdateTrackResponseWindow);
}
, , , OnResponseEvent, UpdateTrackResponseWindow(). ObservableCollection<string>, TrackResponseMessage:
private void UpdateTrackResponseWindow(AbstractResponse message)
{
TrackResponseMessage.Add(FormatMessageResponseToString(message));
}
FormatMessageResponseToString() Track .
: , TrackResponseMessage.Add() . , - Visual Studio 2010.
TrackResponseMessage ViewModel:
public ObservableCollection<String> TrackResponseMessage
{
get { return _trackResponseMessage; }
set
{
_trackResponseMessage = value;
RaisePropertyChanged("TrackResponseMessage");
}
}
Thread, Track, ViewModel? !