下面的兩個代碼段位於不同的名稱空間中。第二個代碼的訪問修飾符是內部的。我正在做一些操作,我想計算MgmntApp進度條中的百分比和更新。我怎樣才能做到這一點?使用內部類中存在的值更新進度條
WpfApplication1
MainWindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Height="204">
<ProgressBar Height="35" HorizontalAlignment="Left" Margin="57,83,0,0" Name="progressBar1" VerticalAlignment="Top" Width="346" />
</Grid>
</Window>
我想在下面的類做了長時間運行的操作以更新進度條的值。
不同
FileParser.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Different
{
/// <summary>
/// </summary>
internal class FileParser:ImageFileParser
{
ImageFileParser.GenerateCmds()
{
percentage=change; //0 to 100
//long time operation
}
}
}
但fp.GenerateCmds()將被另一個名爲PrgmCmdGen的類調用。如何更新用戶界面?(我無法訪問UI的進度欄 – SHRI
不要從邏輯內更新視圖。將PrgmCmdGen類訂閱到事件中,並從PrgmCmdGen類中暴露另一個ProgressChanged事件)並按照我在我的回答中所建議的那樣訂閱它。 –
new ProgressChangedEventArgs(percentage));這是給錯誤。另一個參數UserState它的要求。 – SHRI