一个类似于Windows复制和粘贴功能的弹出框 [英] A pop-up box similar to the windows copy and paste function

查看:112
本文介绍了一个类似于Windows复制和粘贴功能的弹出框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wpf MVVM模型开发

1. UI一个ProgressControl.xaml,用于弹出进度条窗口文件,主要内容如下:

Wpf MVVM model development
1. UI a ProgressControl.xaml, for the pop-up progress bar window file, the following major elements:

<StackPanel>

        <TextBlock  Text="{Binding Caption}"  Style="{StaticResource CaptionText}"/>
        <Border Style="{StaticResource ContentBorder}">
            <StackPanel>
                <StackPanel Style="{StaticResource ContentMessageBorder}">
                    <TextBlock   Text="{Binding Message}" Style="{StaticResource ContentMessage}" />
                    <telerik:RadProgressBar  Minimum="0" Maximum="100" Margin="10,10,10,0"

                     Width="260" Height="25"  Value="{Binding Value}" Visibility="Visible" />
                </StackPanel>
                <StackPanel  Style="{StaticResource ButtonContainer}">
                    <telerik:RadButton Command="{Binding CancelCommand}" Content="{Resx CancelBtnText}" IsCancel="True"  />
                </StackPanel>
            </StackPanel>
        </Border>
    </StackPanel>





对应的VM属性:





Corresponding VM attributes:

bool IsHidden { set; }
string Caption { get; set; }
bool IsVisible { get; set; }
string Message { get; set; }
int Value { get; set; }
ICommand CancelCommand { get; }





2.我在另一台虚拟机中导出图像和弹出进度条,主要代码如下:





2. I export images and pop-up progress bar in another VM, the main code is as follows:

_progressVM.IsVisible = true;
 _progressVM.Caption = "Exporting";

if (modeIndex == "1")
                    {
                        var navImages = NavBarSelectedDocument.DocumentImagesUC_VM.Images.Where(x => x.IsDefaultImage == false).ToList();
                        if (!isExportSplitPage)
                        {
                            navImages = NavBarSelectedDocument.DocumentImagesUC_VM.Images.Where(x => x.IsDefaultImage == false && x.IsSplitPage == false).ToList();
                        }
                        int i = 0;
                        int count = navImages.Count;
                        foreach (var item in navImages)
                        {
                            i++;
                            _progressVM.Message = item.LinkedDocument.Name + "--" + item.Image.Name;
                            _progressVM.Value = ((i * 100) / count);
                            _project.ExportDocument(item.ImagePath, exportPath, item.LinkedDocument.Name, item.Name);
                        }
                    }

_progressVM.IsVisible = false;





上面的代码可以弹出一个很好的进度条窗口,但我现在要取消该功能,即弹出窗口中有一个Cancel按钮,单击取消,弹出窗口关闭,并停止导出图片。我设置正在进行取消按钮绑定命令IsVisible = false,但是不起作用,编辑的注意啊?为了实现这个功能我需要做些什么,追求大神帮助,非常感谢



The code above can be a good progress bar window pops up, but I now want to cancel the function, that is, there is a Cancel button in the pop-up window, click Cancel, the pop-up window is closed, and stop the export picture. I set up in progress Cancel button bindings command IsVisible = false, but does not work, Editor''s Note ah? What do I have to do in order to achieve this functionality, pursuing big God help, thank you very much

推荐答案

尝试使用Thread来执行中止正在运行的导出

Try to use Thread to execute an abort the running export
private System.Threading.Thread thread = new System.Threading.Thread(Export);
private void Export(){
_progressVM.IsVisible = true;
 _progressVM.Caption = "Exporting";
 
if (modeIndex == "1")
                    {
                        var navImages = NavBarSelectedDocument.DocumentImagesUC_VM.Images.Where(x => x.IsDefaultImage == false).ToList();
                        if (!isExportSplitPage)
                        {
                            navImages = NavBarSelectedDocument.DocumentImagesUC_VM.Images.Where(x => x.IsDefaultImage == false && x.IsSplitPage == false).ToList();
                        }
                        int i = 0;
                        int count = navImages.Count;
                        foreach (var item in navImages)
                        {
                            i++;
                            _progressVM.Message = item.LinkedDocument.Name + "--" + item.Image.Name;
                            _progressVM.Value = ((i * 100) / count);
                            _project.ExportDocument(item.ImagePath, exportPath, item.LinkedDocument.Name, item.Name);
                        }
                    }
 
_progressVM.IsVisible = false;
}



点击导出按钮,请致电:


On click Export button, please call:

thread.Start();



点击取消按钮,请致电:


And on Cancel button click, call:

if (thread.IsAlive || thread.IsBackground)
{
   thread.Abort();
}


嗨jerrykid,谢谢你的回答,但是如何隐藏进度窗口的小窗口?



我使用MVVM !!!
Hi jerrykid,thanks your answer,but how to hide the pup-window of progress window?

I use the MVVM!!!


隐藏进度窗口的pup窗口

点击取消按钮点击,致电:



To hide the pup-window of progress window
On Cancel button click, call:

if (thread.IsAlive || thread.IsBackground)
{
   thread.Abort();
   // Put your code here to hide popup window  
}


这篇关于一个类似于Windows复制和粘贴功能的弹出框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆