Exemplo n.º 1
0
 private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.RoutedEvent.Name == "SelectionChanged")
     {
         ListBox item = sender as ListBox;
         if (item.DataContext != null)
         {
             OnlineUserData model = item.SelectedItem as OnlineUserData;
             _mainVM.SeleteManInfo = model;
         }
     }
 }
Exemplo n.º 2
0
 private void RemoveOnlineUser(string userName)
 {
     try
     {
         OnlineUserData user = _vm.OnlineUser.Single(T => T.UserName == userName);
         Application.Current.Dispatcher.Invoke(() => _vm.OnlineUser.Remove(user));
     }
     catch (Exception)
     {
         Application.Current.Dispatcher.Invoke(() => _vm.OnlineUser.Distinct());
         Console.WriteLine("无法移除用户");
     }
 }
Exemplo n.º 3
0
        private void AddOnlineUserData(OnlineUserInfo user)
        {
            OnlineUserData userData = new OnlineUserData();

            userData.UserName = user.UserName;
            if (user.NickName == null || user.NickName == string.Empty)
            {
                userData.NickName = user.UserName;
            }
            else
            {
                userData.NickName = user.NickName;
            }

            if (user.ImageHash != null)
            {
                try
                {
                    string path = _vm.ImagePath + HashHelper.ComputeStringMd5(user.UserName) + ".jpg";
                    if (File.Exists(path))
                    {
                        if (_vm.UserName == user.UserName)
                        {
                            userData.Image = new BitmapImage();
                            FileStream fs  = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                            byte[]     buf = new byte[fs.Length];
                            fs.Read(buf, 0, (int)fs.Length);
                            fs.Close();
                            MemoryStream ms = new MemoryStream(buf);

                            userData.Image.BeginInit();
                            userData.Image.StreamSource     = ms;
                            userData.Image.DecodePixelWidth = 200;
                            userData.Image.CacheOption      = BitmapCacheOption.OnLoad;
                            userData.Image.EndInit();
                            userData.Image.Freeze();
                        }
                        else
                        {
                            userData.Image = new BitmapImage(new Uri(path));
                            userData.Image.Freeze();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            Application.Current.Dispatcher.Invoke(() => _vm.OnlineUser.Add(userData));
        }
Exemplo n.º 4
0
        private void Get_ListBox_Item(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            ListBox item = sender as ListBox;

            if (item.DataContext != null)
            {
                OnlineUserData model = item.SelectedItem as OnlineUserData;
                if (model == null)
                {
                    return;
                }
                _mainVM.SeleteManInfo = model;
            }
        }
Exemplo n.º 5
0
        private void Men_Talk(object sender, RoutedEventArgs e)
        {
            ListBox item = e.Source as ListBox;

            if (item.DataContext != null)
            {
                OnlineUserData model = item.SelectedItem as OnlineUserData;
                if (model == null)
                {
                    return;
                }
                _mainVM.SeleteManInfo = model;
                _mainVM.Talk(model);
            }
        }
Exemplo n.º 6
0
        private void ListBox_Mouse_Double_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            ListBox item = sender as ListBox;

            if (item.DataContext != null)
            {
                OnlineUserData model = item.SelectedItem as OnlineUserData;
                if (model == null)
                {
                    return;
                }
                _mainVM.Islist    = true;
                _mainVM.Directory = "";
                _mainVM.CallLoad(model.UserName);
            }
        }