WPF resource size: does it push it to the scope (app.xaml) for performance?

A) If I have a resource that will be used from a user control, which one is more efficient in terms of performance ...?
To include it in the user control area yourself or refer to a resource from app.xaml ..?

B) Now we have all 100 styles mentioned in appl.xaml. Moving them to the appropriate user controls will be worth the effort.

+4
source share
3 answers

Adding application resources gives you better reuse, but adds complexity because it does not immediately determine which pages use this resource.

Pro Silverlight 4 in C # Matthew MacDonald


In general, this depends on the level of reuse of resources in the application. If the resource is used repeatedly, place it in application resources. If you intend to use the style for only one UserControl and not use it in other places, then placing this style in app.xaml will be excessive. In my opinion, even if the resource is used only for 2-3 pages, it is better to place it on each page.

In terms of performance - I don’t think you have so many resources that can hurt performance.
The following are articles to help you improve download times:

Update:
MSDN helps in many situations) After reading this article you will get answers to many questions: Resource Dictionaries
Resources performance issues article: Silverlight XAML performance issue and shared resources .

+1
source

A) If I have a resource that will be used from a user control, which one is more efficient in terms of performance ...? To include it in the user control area yourself or refer to a resource from app.xaml ..?

Since XAML is compiled into BAML and then loaded at startup, you will not see the differences. Now, most XAML things are common (i.e. Linear brush, drop-down style), so it's best not to put it directly on the control to reuse the same style and factorize

B) Now we have all 100 styles mentioned in appl.xaml. Moving them to the appropriate user controls will be worth the effort.

Effective counter, as you cannot reuse it.

If your XAML is slow and you are using MVVM, check how many objects are created. I had a problem this year, recreating the context menu for each element and leaving it available for all elements (in the tree structure) with improved initialization time.

+2
source

I would place it where it is most logical. If this is something that is used in more than one place or even something that can be used more than once, then put it in app.xaml. If this is very specific to the page window / usercontrol /, put it there.

0
source

Source: https://habr.com/ru/post/1389210/


All Articles