如何设置wpf应用程序中所有用户控件的样式? [英] How set style for all user controls in wpf application?

查看:79
本文介绍了如何设置wpf应用程序中所有用户控件的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

我希望在我的wpf应用程序中更改所有用户控件的后台。我将以下代码添加到Generic.xaml和App.xaml但不工作!!!



Hello.
I want change background for all user controls in my wpf application.I add following code to Generic.xaml and App.xaml but dont work!!!

<Style TargetType="{x:Type UserControl}">
        <Setter Property="Background" Value="LightBlue"/>
    </Style>





有人可以帮我吗?????????

提前致谢

关注



can anybody help me on this please?????????
Thanks in advance
Regards

推荐答案

请查看以下链接



http://stackoverflow.com/questions/632356/wpf-usercontrol-style [ ^ ]



希望有帮助
Kindly check the below link

http://stackoverflow.com/questions/632356/wpf-usercontrol-style[^]

Hope it helps


方法如下:

http://msdn.microsoft.com/en-us/library/ms745683%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/bb384338%28v=vs.110%29.aspx [ ^ ]。



此外,如果您在应用程序中有多个窗口并想要在窗口之间共享样式,则需要将样式放入外部 ResourceDictionary (单独的XML文件)并在所有窗口中使用此字典'XAML:

http://msdn.microsoft.com/en-us/library/cc903952%28v=vs.95%29.aspx [ ^ ],

http://msdn.microsoft.com/en-Us/library/windows/apps/windows.ui.xaml.resourcedictionary.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.resourcedictionary.mergeddictionaries%28v=vs.110%29.aspx [ ^ ]。



-SA
Here is how:
http://msdn.microsoft.com/en-us/library/ms745683%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/bb384338%28v=vs.110%29.aspx[^].

Also, if you have more than one window in the application and want to share the styles between windows, you would need to put the styles in external ResourceDictionary (separate XML file) and use this dictionary in all windows' XAML:
http://msdn.microsoft.com/en-us/library/cc903952%28v=vs.95%29.aspx[^],
http://msdn.microsoft.com/en-Us/library/windows/apps/windows.ui.xaml.resourcedictionary.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.resourcedictionary.mergeddictionaries%28v=vs.110%29.aspx[^].

—SA


这篇关于如何设置wpf应用程序中所有用户控件的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆