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

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

+4
source share
4 answers

App.xaml is part of the XAML Application class - the only centralized place where you define the logic and resources of the application. So far, Generic.xaml , being in the Themes directory of your project, is a dictionary in which you define default styles for all your custom controls. This dictionary is used if there is no Windows-specific dictionary in Themes folder. For example, you might have the following Themes directory structure:

 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 the user control to look the same on any Windows theme, you only need to create Generic.xaml.

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

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

+5
source

App.xaml is used for widespread use of application resources and is always used.

Generic.xaml is used for templates and styles for custom controls and will be used unless you specify a different level or template at the control level.

+1
source

App.xaml is a container for resources at your application level.

Generic.xaml is a resource file for all of your controls that are not based on a custom or standard theme.

+1
source

App.xaml used for wide application resources and therefore may contain links to other XAML resources.

 <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="App"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Themes/ValidationStyles.xaml"/> <ResourceDictionary Source="Themes/ControlStyles.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> 

This allows you to isolate your styles in a given XAML file for manageability and then use the file in the application as it merges into the application at runtime.

generic.xaml used as a standard container for the default style for a custom control. The structure will look in the Themes directory for generic.xaml with style resolution for the given type.

+1
source

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


All Articles