How save/reloaded content of property/richTextBox from slave screen

Dec 25, 2010 at 1:49 PM

Hi, I would like get advance how solve this problem. Excuse me, I am 16 years and my english is not good ;)

I do own chat application (UI  looks like skype ). So I have:

  1.  Master screen with contacts, in code is Messenger screen.
  2.  And slave screen, in code is Chat screen.

My scenario is:

  • Messenger view model recieve messages from my server and publishes this messages on certain  chat screen.
    • For example it arrived message from Tom.
    • It open new WPF window and publish on message from Tom.
  • In chat screen I bind  content of the of comunication on string and also FlowDocument property. Messages are shown in richTextBox control.


My problem is have achieve this behavior?

  • It arrived new message. ->
  • Open new chat screen and show message. ->
  • User send answer. ->
  • Close chat screen. ->
  • Then arrived other message.  ->
  • And I would like open chat screen with history of comunnication.

What is the best way how store history of comunication?  If user is closing chat screen I can publish history of communication on master screen / messenger screen and store history of  the comunication in dictionray<Nick, History>


Master/messenger screen:

    [Export("MessengerScreen", typeof(IMessengerViewModel))]
    public class MessengerViewModel : Screen, IMessengerViewModel, IInitializable<Account>, IHandle<Rp>
        //this method open chat screen
        public IEnumerable<IResult> OpenChatScreen()
            yield return new ShowWindow("ChatScreen")
                .InitializeWith(_service.DetailData(Account, _selectedFriend.Key));

Show window class:

    public class ShowWindow : IResult
        readonly Type _windowType;
        readonly string _name;

        public IShellViewModel Shell { get; set; }

        Action<object> _initializationAction = window => { };

        public ShowWindow InitializeWith<T>(T argument)
            _initializationAction = window =>
                var initializable = window as IInitializable<T>;
                if (initializable != null)
            return this;

        public ShowWindow(string name)
            _name = name;

        public ShowWindow(Type windowType)
            _windowType = windowType;

        public void Execute(ActionExecutionContext context)
            var window = !string.IsNullOrEmpty(_name)
                ? IoC.Get<object>(_name)
                : IoC.GetInstance(_windowType, null);



            Completed(this, new ResultCompletionEventArgs());

        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };

        public static ShowWindow Of<T>()
            return new ShowWindow(typeof(T));

Slave/chat screen:

    [Export("ChatScreen", typeof(IChatViewModel))]
    public class ChatViewModel : Screen, IInitializable<DetailData>, IHandle<Rp>

        //history of the comunication
        public FlowDocument Conversation
            get { return _conversation; }
                _conversation = value;

Dec 25, 2010 at 8:48 PM

Rather than publishing the history on close, you can simply subscribe your persistence component to the same message that the chat screen subscribes to in the first place. As a result, when the chat screen receives the message, it will display it and when the persistence component receives it, it will save it. That would keep your components nicely decoupled. There's lots of ways you could accomplish this. Pick the simplest solution that will work and refactor later if needed.