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

for*_*yez 5 c# wpf

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

Pav*_*kov 6

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
Run Code Online (Sandbox Code Playgroud)

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

因此,基本上您应该Generic.xaml只使用自定义控件和App.xaml其他所有内容定义样式(例如,您的画笔,颜色等,或者您自己的标准控件样式).

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


Ern*_*rno 1

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

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