using DownKyi.Events; using DownKyi.Images; using DownKyi.Utils; using DownKyi.ViewModels.Friends; using DownKyi.ViewModels.PageViewModels; using Prism.Commands; using Prism.Events; using Prism.Regions; using System.Collections.Generic; using System.Collections.ObjectModel; namespace DownKyi.ViewModels { public class ViewFriendsViewModel : BaseViewModel { public const string Tag = "PageFriends"; private readonly IRegionManager regionManager; private long mid = -1; #region 页面属性申明 private VectorImage arrowBack; public VectorImage ArrowBack { get => arrowBack; set => SetProperty(ref arrowBack, value); } private ObservableCollection tabHeaders; public ObservableCollection TabHeaders { get => tabHeaders; set => SetProperty(ref tabHeaders, value); } private int selectTabId; public int SelectTabId { get => selectTabId; set => SetProperty(ref selectTabId, value); } #endregion public ViewFriendsViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) : base(eventAggregator) { this.regionManager = regionManager; #region 属性初始化 ArrowBack = NavigationIcon.Instance().ArrowBack; ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); TabHeaders = new ObservableCollection { new TabHeader { Id = 0, Title = DictionaryResource.GetString("FriendFollowing") }, new TabHeader { Id = 1, Title = DictionaryResource.GetString("FriendFollower") }, }; #endregion } #region 命令申明 // 返回事件 private DelegateCommand backSpaceCommand; public DelegateCommand BackSpaceCommand => backSpaceCommand ?? (backSpaceCommand = new DelegateCommand(ExecuteBackSpace)); /// /// 返回事件 /// private void ExecuteBackSpace() { //InitView(); ArrowBack.Fill = DictionaryResource.GetColor("ColorText"); NavigationParam parameter = new NavigationParam { ViewName = ParentView, ParentViewName = null, Parameter = null }; eventAggregator.GetEvent().Publish(parameter); } // 顶部tab点击事件 private DelegateCommand tabHeadersCommand; public DelegateCommand TabHeadersCommand => tabHeadersCommand ?? (tabHeadersCommand = new DelegateCommand(ExecuteTabHeadersCommand)); /// /// 顶部tab点击事件 /// /// private void ExecuteTabHeadersCommand(object parameter) { if (!(parameter is TabHeader tabHeader)) { return; } // TODO // 此处应该根据具体状态传入true or false NavigationView(tabHeader.Id, true); } #endregion /// /// 进入子页面 /// /// /// private void NavigationView(int id, bool isFirst) { // isFirst参数表示是否是从PageFriends的headerTable的item点击进入的 // true表示加载PageFriends后第一次进入 // false表示从headerTable的item点击进入 NavigationParameters param = new NavigationParameters() { { "mid", mid }, { "isFirst", isFirst }, }; switch (id) { case 0: regionManager.RequestNavigate("FriendContentRegion", ViewFollowingViewModel.Tag, param); break; case 1: regionManager.RequestNavigate("FriendContentRegion", ViewFollowerViewModel.Tag, param); break; } } /// /// 导航到页面时执行 /// /// public override void OnNavigatedTo(NavigationContext navigationContext) { base.OnNavigatedTo(navigationContext); ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); // 根据传入参数不同执行不同任务 var parameter = navigationContext.Parameters.GetValue>("Parameter"); if (parameter == null) { return; } mid = (long)parameter["mid"]; SelectTabId = (int)parameter["friendId"]; NavigationView(SelectTabId, true); } } }