1

I´m creating a smal WPF-Application with 5 Tabs and I´m wondering if it´s a good idea to seperate the tabs into UserControls. I think it is nice because my XAML-Code is about 400 alines and grows but at the other side i think it´s much work to pass the events to my main window and slows it down. Maybe i could work with the events at the UserControls but then I need solutions to have access to variables in my main window.

So what would you recommend me?

1
  • "...to pass the events to my main window and slows it down" - No, it really doesn't. Commented Mar 25, 2011 at 4:09

2 Answers 2

2

It really depends on how simple your application is and how resilient to change it needs to be. If this is a throw away app then no, you don't need to split things out into user controls, but it may make your life a bit easier. We can't tell you what you should do because we don't know your requirements, but creating a user control will definitely make your code easier to change in the future (or during development even) if needed.

Since you mentioned that this is a relatively small app, use this as a general rule; the moment that managing the controls in each tab becomes a problem, wrap them in a UserControl.

but at the other side i think it´s much work to pass the events to my main window and slows it down.

It's not a lot of work and it definitely isn't going to cause performance problems.

Sign up to request clarification or add additional context in comments.

Comments

0

As Ed S. said above, it will definitely not slow your app down. I would recommend you to separate into distinct user controls. More than the XAML weight loss, it will really help you understanding easily your architecture. My personal approach would be "One tab = one UserControl = one ViewModel". I have developed some big applications in WPF, now I can look at them and instantaneously understand what's going on in there, since all parts are separated

4 Comments

o.k., but than i need some static helperclasses(?) to work in all controls with my global variables (like a xml). How do you solve this problem?
I have a "Hub ViewModel" for my main window, which role is to create the other ViewModels bound to each custom control, giving them the parameters needed. Hence, each VM has access to the global variables to be used, and your code is perfectly easy to understand. Once again, it's probably not the only way, MVVM is seen & used differently by all developers... But I'm happy with this one :)
thx again, if you dont mind, can you upload a default project with your custumizations? It would help me alot to understand :-)
have found this article: link but found it a little heavy to understand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.