Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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>
 
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. 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;
 
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
Posted 3-Mar-13 17:06pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi jerrykid,thanks your answer,but how to hide the pup-window of progress window?
 
I use the MVVM!!!
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100