Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: What's the difference between App.xaml and Generic.xaml?

Tags:

c#

wpf

Please let me know the difference between App.xaml and Generic.xaml, I'm confused between these two!

like image 852
Shai UI Avatar asked Feb 11 '11 21:02

Shai UI


People also ask

What is app xaml?

In a Xamarin. Forms application, XAML is mostly used to define the visual contents of a page and works together with a C# code-behind file. The code-behind file provides code support for the markup. Together, these two files contribute to a new class definition that includes child views and property initialization.

What is generic xaml?

xaml file itself, the dictionary entry within generic. xaml can be a merged dictionary whose entries may reference anything.

What is local in xaml?

local is an xml namespace. In this case "local" will be the alias for the namespace AskLocal. It will allow you to declare resources, controls, converters etc from the AskLocal namespace directly in your xaml by using <local:nameofyourcontrol></local:nameofyourcontrol>

What is xaml similar to?

Similar to ASP.NET, XAML provides user interfaces and C# (or VB.NET) is used as code-behind language.


2 Answers

App.xaml is a XAML part of the Application class - the single centralized place where you define application-wide logic and resources. While Generic.xaml, being located in the Themes directory of your project, is a dictionary where you define default styles for all your custom controls. This dictionary is used when there is no windows theme-specific dictionary in the Themes folder. For example, you might have the following structure of the Themes directory:

MyProject
   - Themes
     - Generic.xaml // Default styles if current theme is non of the themes below
     - Classic.xaml // Styles for “Classic” Windows 9x/2000 look on Windows XP.
     - Luna.NormalColor.xaml // Styles for default blue theme on Windows XP.
     - Luna.Homestead.xaml //  Styles for olive theme on Windows XP.
     - Luna.Metallic.xaml // Styles for silver theme on Windows XP.
     - Royale.NormalColor.xaml // Styles for default theme on Windows XP Media Center Edition.
     - Aero.NormalColor.xaml // Styles for default theme on Windows Vista

If you want you custom control to look the same on any windows theme, you need to create only Generic.xaml.

So, basically you should use Generic.xaml only to define styles for your custom control and App.xaml for everything else (e.g. your brushes, color, etc. or your own styles for standard controls).

See also the answer to this question: What is so special about Generic.xaml?

like image 90
Pavlo Glazkov Avatar answered Oct 03 '22 14:10

Pavlo Glazkov


The App.xaml is used for application wide resources and is always used.

Generic.xaml is used for the templates and styles for Custom Controls and will be used when you do not specify an other style or template at control level.

like image 35
Emond Avatar answered Oct 03 '22 16:10

Emond