コード例 #1
0
        /// <summary>
        /// 具体同步项右击事件, 移除项目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImgItemRightClick(object sender, MouseButtonEventArgs e)
        {
            if (mSyncFileBgWorker.IsBusy)
            {
                //正在同步时不允许删除项
                return;
            }
            var subListView = XamlUtil.GetParentListView(e);
            //根据触发按钮获取点击的行
            var selected    = ((ListViewItem)subListView.ContainerFromElement(sender as StackPanel)).Content;
            var ImgItemList = (ObservableCollection <DeviceSyncItem>)subListView.ItemsSource;

            ImgItemList.Remove(selected as DeviceSyncItem);
        }
コード例 #2
0
        /// <summary>
        /// 项目双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImgItemLeftClick(object sender, MouseButtonEventArgs e)
        {
            var subListView = XamlUtil.GetParentListView(e);
            //根据触发按钮获取点击的行
            var selected    = (DeviceSyncItem)((ListViewItem)subListView.ContainerFromElement(sender as StackPanel)).Content;
            var curTimeMill = TimeUtil.CurrentMillis();
            var lastClick   = selected.LastLeftMouseClickTime;

            selected.LastLeftMouseClickTime = curTimeMill;
            //双击才执行操作
            if (curTimeMill - lastClick < 200)
            {
                if (selected.SourceView == SyncDeviceType.PC)
                {
                    //如果文件存在于PC, 则打开文件
                    System.Diagnostics.Process.Start(Path.Combine(selected.FolderView, selected.NameView));
                }
                else
                {
                    //不允许重复调用
                    if (selected.IsCopying)
                    {
                        return;
                    }

                    //读取系统的临时文件夹
                    var winTempFolder = Path.GetTempPath();
                    if (null == winTempFolder)
                    {
                        OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                        {
                            message    = "无法获取临时文件夹",
                            alertLevel = AlertLevel.ERROR,
                        });
                        return;
                    }
                    var targetFullPath = Path.Combine(winTempFolder, selected.NameView);
                    //如果已经存在于临时文件夹, 则直接打开
                    if (System.IO.File.Exists(targetFullPath))
                    {
                        System.Diagnostics.Process.Start(targetFullPath);
                        return;
                    }

                    //发送进度消息
                    selected.IsCopying = true;
                    OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                    {
                        message     = "正在复制文件",
                        alertLevel  = AlertLevel.RUN,
                        nowProgress = 99
                    });
                    //先复制目标文件到临时文件夹, 再打开
                    using (var device = (MediaDevice)DeviceListCombobox.SelectedItem)
                    {
                        device.Connect();
                        var           filePath = Path.Combine(((DeviceDriverViewModel)DriverListCombobox.SelectedItem).ValueView, selected.FolderView, selected.NameView);
                        MediaFileInfo fileInfo = device.GetFileInfo(filePath);
                        fileInfo.CopyTo(targetFullPath);
                        device.Disconnect();
                    }
                    selected.IsCopying = false;
                    OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                    {
                        message = string.Format("已复制到临时文件夹 {0}", targetFullPath)
                    });
                    System.Diagnostics.Process.Start(targetFullPath);
                }
            }
            else
            {
                //显示文件名
                OnTaskBarEvent?.Invoke(new MainWindowStatusNotify
                {
                    message = string.Format("{0}", Path.Combine(selected.FolderView, selected.NameView))
                });
            }
        }