Esempio n. 1
0
        public ChatViewModel(Window window, DisplayedContactModel user, ScrollViewer scroll)
        {
            this.window            = window;
            User                   = user;
            user.OnlineIcoPath     = "pack://application:,,,/ChatApp;component/Resources/Offline.ico";
            AutoScroll             = scroll;
            SendCommand            = new RelayCommand(SendCommandExecute);
            ProfilePicture         = user.ImagePath;
            PersonalProfilePicture = "pack://application:,,,/ChatApp;component/Resources/ProfilePicture.jpg";

            //add fake messages
            //TO DO : Server
            AddFakeMessages();
        }
        public static void OpenChatWindow(DisplayedContactModel displayedContact)
        {
            if (displayedContact == null)
            {
                return;
            }
            UserModel user = new UserModel
            {
                Email     = displayedContact.Name,
                FirstName = displayedContact.Name,
                LastName  = displayedContact.Name,
                IsOnline  = false
            };

            foreach (Window win in App.Current.Windows)
            {
                if (win != null)
                {
                    if (win.Tag != null && win.Tag.ToString() == user.Email + "Child")
                    {
                        win.Focus();
                        return;
                    }
                }
            }
            Window child = new Window();

            child.Tag   = user.Email + "Child";
            child.Title = Resources.ChatWindowTitle;
            var chatControl   = new ChatControl();
            var chatViewModel = new ChatViewModel(child, displayedContact, chatControl.AutoScrollViewer);

            chatControl.DataContext = chatViewModel;
            child.Content           = chatControl;
            child.SizeToContent     = SizeToContent.WidthAndHeight;
            child.Icon = BitmapFrame.Create(new Uri("pack://application:,,,/Resources/Chat.ico", UriKind.RelativeOrAbsolute));
            child.Show();
        }