1

我有这段代码,它成功地将使用 LING 的数组中的 XML 文件写入 XML。

XDocument docXML = new XDocument(
            new XDeclaration("1.0", "UTF-8", "yes"),
            new XElement("recordings",
                from Recording r in GetRecordings(ctrl_inFileDir.Text, wmcTypes,     ctrl_useMCEDir.Checked, ctrl_mceDir.Text)
                select new XElement("Recording",
                       new XElement("oid", r.oid),
                       new XElement("name", r.name),
                       new XElement("channel", r.channel),
                       new XElement("filename",r.filename),
                       new XElement("status",r.status),
                       new XElement("startTime",r.startTime),
                       new XElement("endTime",r.endTime),
                       new XElement("Event",
                           new XElement("OID",r.EventOID),
                           new XElement("Title",r.EventTitle),
                           new XElement("SubTitle",r.EventSubTitle),
                           new XElement("Description",r.EventDescription),
                           new XElement("ChannelOID",r.EventOID),
                           new XElement("StartTime",r.EventStartTime),
                           new XElement("EndTime",r.EventEndTime)))
    )
    ); 

我想更新我的对话框上的控件以更新 xml 创建的进度。我可以在这里做吗?如果有怎么办?

4

1 回答 1

0

我不认为你可以用 linq 来实现这一点,你应该做这样的事情

namespace WpfApplication4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
   public partial class MainWindow : Window
   {
    BackgroundWorker _backgroundWorker = new BackgroundWorker();  
      public MainWindow()
      {
          InitializeComponent();
          _backgroundWorker.DoWork += _backgroundWorker_DoWork;
          _backgroundWorker.ProgressChanged += _backgroundWorker_ProgressChanged;
          _backgroundWorker.WorkerReportsProgress = true;  
         _backgroundWorker.RunWorkerAsync(); 


    }

    void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        var  recordings  = GetRecordings(ctrl_inFileDir.Text, wmcTypes,     ctrl_useMCEDir.Checked, ctrl_mceDir.Text);  
        int recCount =  recordings.Count; 
        int i=0 ;  
        foreach (var recording in recordings )
        {
            XElement  xDoc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),new  XElement("Recording",
                   new XElement("oid", r.oid),
                   new XElement("name", r.name),
                   new XElement("channel", r.channel),
                   new XElement("filename",r.filename),
                   new XElement("status",r.status),
                   new XElement("startTime",r.startTime),
                   new XElement("endTime",r.endTime),
                   new XElement("Event",
                       new XElement("OID",r.EventOID),
                       new XElement("Title",r.EventTitle),
                       new XElement("SubTitle",r.EventSubTitle),
                       new XElement("Description",r.EventDescription),
                       new XElement("ChannelOID",r.EventOID),
                       new XElement("StartTime",r.EventStartTime),
                       new XElement("EndTime",r.EventEndTime));
            _backgroundWorker.ReportProgress(i/recCount);


        }
    }

    void _backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        prgBar.Value = e.ProgressPercentage;  
    }

}

希望这个帮助

于 2013-10-27T01:34:18.753 回答