Wpf 应用程序中定义的样式。资源不应用于控件
我试图将全局应用程序样式应用于某些控件类型,但是将这些样式添加到应用程序中。参考资料没有将这些样式应用于我视图中的元素 例如:Wpf 应用程序中定义的样式。资源不应用于控件,wpf,xaml,.net-4.0,styling,Wpf,Xaml,.net 4.0,Styling,我试图将全局应用程序样式应用于某些控件类型,但是将这些样式添加到应用程序中。参考资料没有将这些样式应用于我视图中的元素 例如: <Application x:Class="GUI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application x:Class="GUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="AliceBlue"></Setter>
<Setter Property="Margin" Value="20,20,20,20"></Setter>
<Setter Property="FontStyle" Value="Italic"></Setter>
</Style>
</Application.Resources>
</Application>
在我发现的所有应用程序范围样式的示例中,他们都是这么说的,但这对我不起作用。我做错了什么
谢谢,
Alex。我自己解决了这个问题,woops,问题是我没有使用
StartUpUri
属性打开我的初始应用程序视图,我更改了我的启动过程,所以它确实使用了这个属性,这解决了我的问题
我的App.xaml现在看起来像这样:
<Application x:Class="GUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="/Views/Application/SplashView.xaml">
<Application.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Aqua"></Setter>
</Style>
</Application.Resources>
</Application>
谢谢,
亚历克斯。尽管这是一篇旧帖子,已经得到回复。我遇到了这个问题。我删除了
StartupUri
并添加了空样式(我以问题为例):
<Application x:Class="GUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<!-- Added blank style first -->
<Style TargetType="Rectangle" />
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="AliceBlue"></Setter>
<Setter Property="Margin" Value="20,20,20,20"></Setter>
<Setter Property="FontStyle" Value="Italic"></Setter>
</Style>
</Application.Resources>
</Application>