using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; using System.Windows.Threading; using HeBianGu.General.WpfControlLib; using HeBianGu.Service.Mvc; using Hopetry.ViewModel.Send; namespace HeBianGu.App.Disk { [ViewModel("Send")] internal class SendViewModel : MvcViewModelBase { private LinkAction _uploadingAction; //正在上传 private LinkAction _completeAction; //上传完成 public LinkAction DownLinkAction; protected override void Init() { ITransitionWipe wipe = new CircleWipe(); DownLinkAction = new LinkAction() { Action = "Down", Controller = "Send", DisplayName = "下载 0", Logo = "\xe891", TransitionWipe = wipe }; LinkActions.Add(DownLinkAction); // 正在上传 _uploadingAction = new LinkAction() { Action = "UpLoad", Controller = "Send", DisplayName = "正在上传", Logo = "\xe6f3", TransitionWipe = wipe }; LinkActions.Add(_uploadingAction); _completeAction = new LinkAction() { Action = "CompleteUpload", Controller = "Send", DisplayName = "上传完成", Logo = "\xe613", TransitionWipe = wipe }; LinkActions.Add(_completeAction); //LinkActions.Add(new LinkAction() { Action = "Down", Controller = "Send", DisplayName = "文件快传", Logo = "\xe764" }); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { SelectLink = LinkActions[0]; })); UpLoadItems.CollectionChanged += (s, e) => { UpdateUploadingItems(); }; } protected override void Loaded(string args) { } #region 文件上传 //上传文件总数 private ObservableCollection _upLoadItems = new ObservableCollection(); /// 说明 public ObservableCollection UpLoadItems { get { return _upLoadItems; } set { _upLoadItems = value; //UpdateUploadingItems(); RaisePropertyChanged("UpLoadItems"); } } //已上传完成文件 private ObservableCollection _completeItems = new ObservableCollection(); public ObservableCollection CompleteItems { get { return _completeItems; } private set { _completeItems = value; RaisePropertyChanged("CompleteItems"); } } // 只读属性,返回过滤后的集合(动态计算) private ObservableCollection _uploadingItems = new ObservableCollection(); public ObservableCollection UploadingItems { get { return _uploadingItems; } private set { _uploadingItems = value; RaisePropertyChanged("UploadingItems"); } } // 在 UpLoadItems 变化时更新 UploadingItems public void UpdateUploadingItems() { UploadingItems = new ObservableCollection( UpLoadItems?.Where(item => item.Value3 != "已完成") ?? Enumerable.Empty() ); } //文件上传进度 private double _progress; public double Progress { get { return _progress; } set { if (_progress != value) { _progress = value; RaisePropertyChanged("Progress"); } } } //上传文件个数 private string _filecount; public string FileCount { get { return _filecount; } set { if (_filecount != value) { _filecount = value; RaisePropertyChanged("FileCount"); } } } //上传完成文件个数 private int _uploadingcount; public int UploadingCount { get { return _uploadingcount; } set { if (_uploadingcount != value) { _uploadingcount = value; _uploadingAction.FullName = "(" + _uploadingcount + ")"; RaisePropertyChanged("UploadingCount"); } } } //上传文件个数 private int _completecount; public int CompleteCount { get { return _completecount; } set { if (_completecount != value) { _completecount = value; _completeAction.FullName = "(" + _completecount + ")"; RaisePropertyChanged("CompleteCount"); } } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } }