Esempio n. 1
0
        public MainWindowViewModel()
        {
            FriendServer friendServer = new FriendServer();
            DataTable    table        = friendServer.GetTable();

            foreach (DataRow item in table.Rows)
            {
                using (MemoryStream memory = new MemoryStream((byte[])item["Head"]))
                {
                    Bitmap       bitmap = (Bitmap)System.Drawing.Image.FromStream(memory);
                    BitmapSource source = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    friends.Add(new Friend()
                    {
                        Nickname = item["Nickname"].ToString(), Head = source
                    });
                }
            }
            CloseCommand = new DelegateCommand(() => {
                Application.Current.Shutdown();
            });

            SelectItemChangedCommand = new DelegateCommand <object>((p) => {
                ListView lv = p as ListView;
                friend      = lv.SelectedItem as Friend;

                //Head= friend.Head;
                //Nickname = friend.Nickname;
            });
            AddCommand = new DelegateCommand(() =>
            {
                addWindow = new AddWindow();
                addWindow.ShowDialog();
            });
            ClickCommand = new DelegateCommand(() =>
            {
                MessageBox.Show("你好");
            });
            CaptureCommand = new DelegateCommand(() =>
            {
                CaptureWindow captureWindow = new CaptureWindow();
                captureWindow.ShowDialog();
            });
        }
Esempio n. 2
0
        public AddWindowViewModel()
        {
            page = listControl;
            addUserControl.model = this;
            FriendServer friendServer = new FriendServer();
            DataTable    table        = friendServer.GetTable();

            foreach (DataRow item in table.Rows)
            {
                using (MemoryStream memory = new MemoryStream((byte[])item["Head"]))
                {
                    Bitmap       bitmap = (Bitmap)System.Drawing.Image.FromStream(memory);
                    BitmapSource source = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    fri.Add(new Friend()
                    {
                        Nickname = item["Nickname"].ToString(), Head = source
                    });
                }
            }
            SearchCommand = new DelegateCommand(() =>
            {
                newfri.Clear();
                page            = addUserControl;
                FriendServer se = new FriendServer();
                DataTable tabel = se.GetData(text.ToString());
                for (int i = 0; i < tabel.Rows.Count; i++)
                {
                    Friend fg   = new Friend();
                    fg.Nickname = tabel.Rows[i]["Nickname"].ToString();
                    using (MemoryStream memory = new MemoryStream((byte[])tabel.Rows[i]["Head"]))
                    {
                        Bitmap bitmap       = (Bitmap)System.Drawing.Image.FromStream(memory);
                        BitmapSource source = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        fg.Head             = source;
                    }
                    newfri.Add(fg);
                }
            });
        }