WPF:App.xaml和Generic.xaml有什么区别?

请告诉我App.xaml和Generic.xaml之间的区别,我对这两者感到困惑!

App.xaml是Application类的XAML部分 – 您可以在其中定义应用程序范围的逻辑和资源的单一集中位置。 Generic.xaml位于项目的Themes目录中,是一个字典,您可以在其中为所有自定义控件定义默认样式。 当Themes文件夹中没有特定于Windows主题的字典时,将使用此字典。 例如,您可能具有以下Themes目录的结构:

 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 

如果您希望自定义控件在任何Windows主题上看起来相同,则只需创建Generic.xaml。

所以,基本上你应该只使用Generic.xaml为你的自定义控件定义样式,为其他一切定义App.xaml (例如你的画笔,颜色等,或者你自己的标准控件样式)。

另请参阅这个问题的答案: Generic.xaml有什么特别之处?

App.xaml用于应用程序范围的资源,并始终使用。

Generic.xaml用于自定义控件的模板和样式,并且在未在控件级别指定其他样式或模板时使用。

App.xaml是应用程序级资源的容器。

Generic.xaml是所有控件的资源文件,不基于自定义或默认主题。

App.xaml用于应用程序范围的资源,因此可以包含对其他XAML资源的引用。

           

这允许您在给定的XAML文件中隔离样式以实现可管理性,然后在应用程序中使用该文件,因为它在运行时被合并到应用程序中。

generic.xaml用作默认自定义控件默认样式的容器。 在解析给定类型的样式时,框架将在Themes目录中查找generic.xaml