以WPF样式合并资源 [英] Merge Resource in WPF Styles
本文介绍了以WPF样式合并资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在WPF中开发一个项目
并在XAML中的app.xaml中添加了样式文件,为
I am developing a project in WPF
and has added a styling file in XAML in the app.xaml as
<application x:class="JIMS.App" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Home.xaml">
<application.resources>
<resourcedictionary source="Skins/Style.xaml" />
</application.resources>
</application>
然后在Style.xaml中作为
and then in the Style.xaml as
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<resourcedictionary.mergeddictionaries>
<resourcedictionary source="Brushes.xaml" />
<resourcedictionary source="Button.xaml" />
<resourcedictionary source="Controls.xaml" />
</resourcedictionary.mergeddictionaries>
</resourcedictionary>
对于某些控件,我没有使用样式键,而是将目标指定为该控件iteslf ..我希望将该样式应用于项目中的所有控件...
For certain controls i have not used key in style and gave target as that control iteslf.. I want that style to be applied to all the controls in my project...
<Style TargetType="{x:Type TextBox}">
<setter property="Height" value="25"></setter>
<setter property="BorderBrush" value="#444444"></setter>
<setter property="Margin" value="0,2,0,2"></setter>
</Style>
但是,即使我能够看到在Visual Studio Designer窗口中应用的样式,但这种样式并不适用于应用程序中的所有控件,但RunTIme
but this style is not appling for all the controls in the Application even though i am able to see the style applied in the Visual Studio Designer window but no result in RunTIme
推荐答案
尝试在合并字典的字典中添加虚拟的默认样式.
< resourcedictionary xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml">
< resourcedictionary.mergeddictionaries>
< resourcedictionary source ="Brushes.xaml"/>
< resourcedictionary source ="Button.xaml"/>
< resourcedictionary source ="Controls.xaml"/>
</resourcedictionary.mergeddictionaries>
</resourcedictionary>
< style targettype ="Control" based on ="{StaticResource {x:Type Control}}""/>
这应该工作
Try to add a dummy default style in a dictionary, where you merge dictionaries.
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<resourcedictionary.mergeddictionaries>
<resourcedictionary source="Brushes.xaml" />
<resourcedictionary source="Button.xaml" />
<resourcedictionary source="Controls.xaml" />
</resourcedictionary.mergeddictionaries>
</resourcedictionary>
<style targettype="Control" basedon="{StaticResource {x:Type Control}}" />
This should work
这篇关于以WPF样式合并资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文