Frage

A) If I have a resource to be used from a user control, which one is more good performance wise..?
To include it in the user control scope itself or refer the resource from app.xaml..?

B) Now we have all the 100s of styles referred from appl.xaml. Will moving them to their respective user controls be worth the effort..?

War es hilfreich?

Lösung

Adding an application resources gives you better reuse, but it adds complexity because it's not immediately clear which pages use a given resource.

Pro Silverlight 4 in C# By Matthew MacDonald


Overall it depends on level of reusing Resources in scope of application. If resource is widely reused - then place it in application resources. If you're going to use style only for one UserControl and do not use it in other places - then placing this style within app.xaml will be overabundant. For my opinion even if resource is used only for 2-3 pages it's better to place it in each page.

From performance point of view - I don't think that you've got such amount of resources that could hurt performance.
Below are articles that could help you to improve loading time:

Update:
MSDN helps in many situations) After reading this article, you'll get answers for many questions: Resource Dictionaries
Article that describes Resources performance issues: Silverlight XAML Performance Problem and Shared Resources.

Andere Tipps

A) If I have a resource to be used from a user control, which one is more good performance wise..? To include it in the user control scope itself or refer the resource from app.xaml..?

Since XAML is compiled in BAML and then loaded at startup, you'll not see differences. Now most of XAML things are shared (ie. a linearbrush, a dropdown style) so it is better not not put it directly on the control for reuse same style and factorize

B) Now we have all the 100s of styles referred from appl.xaml. Will moving them to their respective user controls be worth the effort..?

Counter productive, since you'll not be able to reuse them.

If your XAML is slow and you are using MVVM, check how many object are created. I had a problem this year by recreating a context menu for each item, and leave it shared to all items (in a treeview) improved initialization time.

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top