2
0

Workspace.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Controls.Primitives;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. using WechatBakTool.Model;
  21. using WechatBakTool.ViewModel;
  22. namespace WechatBakTool.Pages
  23. {
  24. /// <summary>
  25. /// Workspace.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class Workspace : Page
  28. {
  29. public WXUserReader? UserReader { get; set; }
  30. private WorkspaceViewModel ViewModel { get; set; } = new WorkspaceViewModel();
  31. public Workspace()
  32. {
  33. InitializeComponent();
  34. DataContext = ViewModel;
  35. UserBakConfig? config = Main2.CurrentUserBakConfig;
  36. if (config != null)
  37. {
  38. UserReader = new WXUserReader(config);
  39. if (config.Decrypt)
  40. {
  41. ViewModel.Contacts = UserReader.GetWXContacts();
  42. }
  43. }
  44. }
  45. private void btn_read_Click(object sender, RoutedEventArgs e)
  46. {
  47. if (Main2.CurrentUserBakConfig == null)
  48. {
  49. MessageBox.Show("工作区配置加载失败,请检查配置文件是否正常","错误");
  50. return;
  51. }
  52. }
  53. private void list_users_SelectionChanged(object sender, SelectionChangedEventArgs e)
  54. {
  55. ViewModel.WXContact = list_users.SelectedItem as WXContact;
  56. if(ViewModel.WXContact == null || UserReader == null)
  57. {
  58. return;
  59. }
  60. List<WXMsg>? msgs = UserReader.GetWXMsgs(ViewModel.WXContact.UserName);
  61. list_msg.ItemsSource = msgs;
  62. }
  63. private void txt_find_user_TextChanged(object sender, TextChangedEventArgs e)
  64. {
  65. if (UserReader == null)
  66. return;
  67. string findName = txt_find_user.Text;
  68. if (txt_find_user.Text == "搜索...")
  69. findName = "";
  70. ViewModel.Contacts = UserReader.GetWXContacts(findName);
  71. }
  72. private void txt_find_user_GotFocus(object sender, RoutedEventArgs e)
  73. {
  74. if (txt_find_user.Text == "搜索...")
  75. txt_find_user.Text = "";
  76. Debug.WriteLine(ViewModel.SearchString);
  77. }
  78. }
  79. }