Please let me know the difference between App.xaml and Generic.xaml, I'm confused between these two!
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.
xaml file itself, the dictionary entry within generic. xaml can be a merged dictionary whose entries may reference anything.
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>
Similar to ASP.NET, XAML provides user interfaces and C# (or VB.NET) is used as code-behind language.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With