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