Answered Performance of a user control of many UI elements

  • 16 aprilie 2012 13:26
     
     

    Hi,

    I have  a WPF user control with few tabs and the tabs contains number of text boxes and comboboxes. I'm using MVVM and the business behind is optimized and fast.

    Somehow it takes some time to load the control and the delay is within the Initializing. Is there a way to optimize this ?

    Any advice is appreciated.

    Thanks

    Vipster

Toate mesajele

  • 17 aprilie 2012 07:42
     
     

    Hi,

    I have  a WPF user control with few tabs and the tabs contains number of text boxes and comboboxes. I'm using MVVM and the business behind is optimized and fast.

    Somehow it takes some time to load the control and the delay is within the Initializing. Is there a way to optimize this ?

    Any advice is appreciated.

    Thanks

    Vipster

    Hi,

    Is there a way to virtualize as similar to virtualizing collection data , for UI controls or a technique like lazy loading ?

    Thanks

    Vipster

  • 18 aprilie 2012 04:30
    Moderator
     
     Răspuns

    Hi Vipster,

    You can dynamically add controls into tabs when TabItem selected as below method: 

    In the TabItem’s PreviewMouseDown event (not MouseDown event, since MouseDown has its
    default implementation), you can add something like:

    StackPanel sp = new StackPanel();

    //Add controls to the StackPane.

    tabItem1.Content = sp;

    If you
    don’t want to load the content every time the user clicks it, you can cache it.
    Simply change the StackPanel to a class field.<o:p></o:p>

    private StackPanel sp;

    This will
    create a null StackPanel, so it won’t use memory if the user hasn’t clicked it.
    Now in the event handle:

    if (sp == null)

    {

    sp = new StackPanel();

    tabItem1.Content = sp;

    }

    Hope it helps.

    If you have any additional questions, please feel free to let me know.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us


  • 19 aprilie 2012 08:17
     
     

    Hi,

    Thanks Annabella. Let me try this out and update you with the findings.

    Thanks

    Vipster

  • 26 aprilie 2012 05:58
    Moderator
     
     

    Hi Vipstercular,

    Haven't heard from your for a week, so we are temporarily marking this as "Answer", if you have any concerns or new findings; please feel free to let me know.
    Best regards.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us