Inside string[] FileNames files for archiving. They can somehow attach the counter.

  var cmpr = new SevenZipCompressor(); cmpr.CompressionLevel = CompressionLevel.Fast; //cmpr.ArchiveFormat = OutArchiveFormat.SevenZip; if (File.Exists(FullNameArchive) == true) { cmpr.CompressionMode = CompressionMode.Append; } else { cmpr.CompressionMode = CompressionMode.Create; } //cmpr.CompressDirectory(@"ΠΏΡƒΡ‚ΡŒ\ΠΊ\ΠΏΠ°ΠΊΡƒΠ΅ΠΌΠΎΠΉ\ΠΏΠ°ΠΏΠΊΠ΅", @"имя\Π°Ρ€Ρ…ΠΈΠ²Π°"); cmpr.CompressFiles(FullNameArchive, FileNames); 

.

 <ProgressBar Height="20" VerticalAlignment="Top"/> 
  • Does SevenZipCompressor give messages about the progress of the operation? - VladD

1 answer 1

The official code sample can be found at CodePlex . As the CodePlex closes soon, here is the squeeze:

 // модСль double progress; double Progress { get => progress; set { if (progress != value) { progress = value; // отправляСтС Π½ΠΎΡ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΡŽ ΠΎΠ± ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΈ прогрСсса } } } 
 Progress = 0; cmpr.Compressing += OnCompressingProgress; cmpr.CompressionFinished += OnCompressionFinished; cmpr.BeginCompressFiles(...); // асинхронная опСрация 
 void OnCompressingProgress(object sender, ProgressEventArgs e) => Progress += e.PercentDelta / 100.0; void OnCompressionFinished(object sender, EventArgs e) { Progress = 1.0; var cmpr = (SevenZipCompressor)sender; cmpr.Compressing -= OnCompressingProgress; cmpr.CompressionFinished -= OnCompressionFinished; } 

At the VM level, you need to subscribe for notifications from the model, perhaps smashall them into a UI thread, and update the CompressionProgress INPC property. (This is a different property, not one that is in the model!)

At the View level, you simply bind to the CompressionProgress property of the VM:

 <ProgressBar Value="{Binding CompressionProgress}" Minimum="0" Maximum="1"/> 

Like everything.

  • does not work. need something else? - codename0082016
  • Is it necessary to place all this in .xaml.cs or can it be in any class? - codename0082016
  • @ codename0082016: Eeee ... What does "not working" mean? Let's code in the studio. - VladD
  • @ codename0082016: The model part should be placed in the model layer of your application. VM-part - in the VM-layer, UI-part in the UI-layer. This, in theory, is not just different classes, but little-connected parts of the application. You are using the MVVM pattern, right? - VladD
  • Where should CompressionProgress be located? Value = "{Binding CompressionProgress}" - codename0082016