Beispiel #1
0
        private void SetMessage(Message p, Brush color)
        {
            var pair = new SpecialPairViewModel(p.From, p.To);

            if (!_messages.ContainsKey(pair))
            {
                _messages[pair] = new ObservableCollection <MessageViewModel>();
            }

            var collection = _messages[pair];

            var messageViewModel = new MessageViewModel
            {
                Name  = p.From.Name,
                Text  = p.Text,
                Color = color
            };

            collection.Add(messageViewModel);

            MessagesList.SelectedIndex = collection.Count - 1;
        }
Beispiel #2
0
        public MessageListBox(IEventAggregator eventAggregator)
            : this()
        {
            _eventAggregator = eventAggregator;

            _eventAggregator.GetEvent <MessageReceivedEvent>().Subscribe(p =>
            {
                SetMessage(p, Brushes.DeepSkyBlue);
            }, ThreadOption.UIThread, true);

            _eventAggregator.GetEvent <MessageSentEvent>().Subscribe(m =>
            {
                SetMessage(m, Brushes.DeepPink);
            }, ThreadOption.UIThread, true);

            _eventAggregator.GetEvent <SelectUserEvent>().Subscribe(u =>
            {
                var specialPair = new SpecialPairViewModel(u, _me);
                if (!_messages.ContainsKey(specialPair))
                {
                    _messages[specialPair] = new ObservableCollection <MessageViewModel>();
                }

                var collection             = _messages[specialPair];
                MessagesList.ItemsSource   = collection;
                MessagesList.SelectedIndex = collection.Count - 1;
            }, ThreadOption.UIThread, true);

            _eventAggregator.GetEvent <ConnectedToServerEvent>().Subscribe(c =>
            {
                if (c?.Me != null)
                {
                    _me = c.Me;
                }
            }, ThreadOption.UIThread, true);
        }