TheJoeIaut
TheJoeIaut

Reputation: 1532

WPF Performance Issues

I have a WPF Application which allows user to enter production Data.

For that reason i created a Usercontrol which uses an WPF Toolkit Accordion. In Code behind i create 15 Accordion Items. Each Item has an Stackpanel and 5-10 Textboxes in it.

When adding 12 of these controls to the main Content Control it takes about 10 seconds.

What can be the cause of this behaviour?

    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);

            }
        }
    }

Upvotes: 0

Views: 397

Answers (1)

Breealzibub
Breealzibub

Reputation: 8095

I too experience terrible performance with the Accordion control in the WPF Toolkit. I have an Accordion control within a tab, and whenever I switch to that tab it takes a solid 2-3 seconds to initialize the contents. I do not have this problem when the Accordion Control is not being used.

I think the Accordion is your culprit.

Upvotes: 1

Related Questions