4

I would like to know how to handle large XAML files.

I found this Split one big XAML in number of Sub-XAML files

which mentions that an xml file can be split in several smaller files.

So my question is: is this the only way to deal (develop + maintain) with larger interfaces / XAML files?

Are there other ways?

I would like to

  • have smaller files
  • have designer support and visual studio
  • making it easier to maintain and update it
Community
  • 1
  • 1
Patrick
  • 3,073
  • 2
  • 22
  • 60
  • Why do you suspect this is not the best way? – Domysee Dec 18 '15 at 10:24
  • Because I am a total newbie. Found this solution on my own and never ever found it in the books or tutorial I am studying on. What's more even here when people posts question show sometimes complicated xamls not splitting them in sub-xamls – Patrick Dec 18 '15 at 10:25
  • 2
    You may want to look up Data Templates and Resources. – Steve Dec 18 '15 at 10:26
  • Found here http://wpftutorial.net/DataTemplates.html that it's a way of replacing attributes. From your comment I get it s another way of splitting xamls right? – Patrick Dec 18 '15 at 10:29

2 Answers2

2

Building the UI from parts is very well possible.

Have a look at:

  • UserControls, to reuse UI and logic,
  • CustomControls, to reuse UI and logic and allow a developer to apply his own UI design and
  • DataTemplates and ControlTemplates, to reuse UI

Because Visual Studio 'understands' these concepts you will have designer and compiler support and you won't need to perform additional build steps.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • It's very possible but is it the most convient way to deal with large xaml? As for how to do it what you says coincides with http://stackoverflow.com/questions/4977872/split-one-big-xaml-in-number-of-sub-xaml-files – Patrick Dec 18 '15 at 12:39
  • That depends on your goals. What is 'Convenient' to you might not be convenient others. What is bothering you? What are you trying to solve? – Emond Dec 18 '15 at 12:48
  • 1
    I am trying to improve "standing on the shoulders of giants" as Newton said. I can understand that convenience is opinable. That being said I think that if I split xaml in subxaml I can deal with them more easily. Just like having subroutines instead than a single program flow. At the moment I have a single very long xaml and find it difficult to maintain it (find the right point where to make a correction e.g.) and expanding (adding a new component). So i thought that if I split it in several files it might be easier. NO OTHER SOLUTION comes to my mind though. – Patrick Dec 18 '15 at 12:57
  • By using user controls and templates you will split the file and make it smaller. And you will still have designer support and visual studio will understand what you are doing. – Emond Dec 18 '15 at 13:18
  • Thanx in the end even if downvoter and on hold I had what I've been looking for. – Patrick Dec 18 '15 at 13:33
  • 1
    The reason the question got down voted is that it is asking for a "best way" which is an opinion. If you rephrase the question to "how to cope with large XAML files" it might get up votes and be active again – Emond Dec 18 '15 at 13:47
  • 1
    I edited the question to make it fit the site's goals better. Feel free to rollback the edit – Emond Dec 18 '15 at 14:02
-1

In C# WPF the rule is to have one xaml file by HCI view, so that in MVVM you have a VM for a xaml file.