2012-04-05 111 views
0

我有一個允許用戶輸入生產數據的WPF應用程序。WPF性能問題

因此我創建了一個使用WPF Toolkit Accordion的UserControl。在後面的代碼中,我創建了15個手風琴項目。每個項目都有一個Stackpanel和5-10個文本框。

將這12個控件添加到主內容控件時,大約需要10秒。

這種行爲的原因是什麼?

public XXXMeasurementControl(Measurement meas) 
    { 

     InitializeComponent(); 


     if (meas.ID == -2) 
     { 
      LineNameTextBlock.Text = "Total"; 
     } 
     else 
     { 
      LineNameTextBlock.Text = meas.MeasureDate.ToString("HH:mm") + " - " + meas.MeasureDate.AddHours(1).ToString("HH:mm"); 
     } 



     this.cells = meas.MainCells; 
     this.meas = meas; 


     Binding b = new Binding(); 
     Remark.DataContext = Meas; 
     b.Mode = BindingMode.TwoWay; 
     b.Path = new PropertyPath("Remark"); 
     BindingOperations.SetBinding(Remark, TextBox.TextProperty, b); 

     //Create Cells Start 

     foreach (Cell c in cells) 
     { 
      //Creating Textboxes & Bindings for Stations from Maincells 

      if (c.Name != "OQC") 
      { 

       //Setting Qualified Overall (=Qualified from Cell Appearance Check) 

       Common.BindTextBlock(QualifiedOverallTextBlock, c, "Qualified"); 

       if (c.Name.Contains("Appearance Check")) 
        Common.BindTextBlock(QualifiedOverallTextBlock, c, "Qualified"); 

       //Setting Scrap Rate (=Waste from Cell Acoustic Test) 

       if (c.Name.Contains("Acoustic Test")) 
         Common.BindTextBlock(ScrapRateTextBlock, c, "WasteRate"); 

       AccordionItem aci = new AccordionItem(); 

       StackPanel sp = new StackPanel(); 
       StackPanel groupData = new StackPanel(); 
       StackPanel all = new StackPanel(); 
       all.Children.Add(sp); 
       all.Children.Add(groupData); 

       if (c.Stations != null) 

        //All Single Cell Line Controls 

        if (meas.ID != -2) 
        { 
         for (int i = 0; i < c.Stations.Count; i++) 
         { 
          NumberTextbox t = Common.CreateNumberTextbox(c.Stations[i], "Value", BindingMode.TwoWay, false, null, 80, 22); 

          t.LostFocus += new RoutedEventHandler(t_LostFocus); 

          c.Stations[i].PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(LineControl_PropertyChanged); 

          //Handling if Qualified Field is Editable 

          if (c.Stations[i].Name.Contains("Qualified")) 
          { 
           t.Background = new SolidColorBrush(Colors.BlanchedAlmond); 
           groupData.Children.Add(t); 

          } 
          else 
          { 
           sp.Children.Add(t); 
          } 

         } 
        } 


       groupData.Children.Add(Common.CreateNumberTextbox(c, "RejectQty", BindingMode.OneWay, true,null, 80, 22)); 
       groupData.Children.Add(Common.CreateNumberTextbox(c, "PassRate", BindingMode.OneWay, true, new SolidColorBrush(Colors.BlanchedAlmond), 80, 22)); 
       groupData.Children.Add(Common.CreateNumberTextbox(c, "RejectRate", BindingMode.OneWay, true, new SolidColorBrush(Colors.BlanchedAlmond), 80, 22)); 

       aci.Header = ""; 
       aci.Content = all; 
       MainCellsAccordion.Items.Add(aci); 

      } 
     } 
    } 

回答

1

我也經歷可怕性能在WPF工具包中的手風琴控制。我有一個選項卡內的Accordion控制,每當切換到該選項卡時,需要2-3秒才能初始化內容。當沒有使用手風琴控制時,我沒有這個問題。

我認爲手風琴是你的罪魁禍首。