WPF ControlTemplate样式未在生成模式中显示
对于我当前的应用程序,第一次在WPF中,唯一要做的就是设计我的按钮。问题是,我应用的样式确实会显示在设计器中,但一旦我构建了应用程序,样式就不会显示 我将演练中的示例按钮样式复制到了我的application.xaml中:WPF ControlTemplate样式未在生成模式中显示,wpf,vb.net,visual-studio-2017,Wpf,Vb.net,Visual Studio 2017,对于我当前的应用程序,第一次在WPF中,唯一要做的就是设计我的按钮。问题是,我应用的样式确实会显示在设计器中,但一旦我构建了应用程序,样式就不会显示 我将演练中的示例按钮样式复制到了我的application.xaml中: <Application x:Class="Application" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VideoManager"
StartupUri="MainWindow.xaml"
ShutdownMode="OnMainWindowClose">
<Application.Resources>
<!--Define a template that creates a gradient-colored button.-->
<LinearGradientBrush x:Key="GrayBlueGradientBrush" StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="DarkGray" Offset="0" />
<GradientStop Color="#CCCCFF" Offset="0.5" />
<GradientStop Color="DarkGray" Offset="1" />
</LinearGradientBrush>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="{StaticResource GrayBlueGradientBrush}" />
<Setter Property="Width" Value="80" />
<Setter Property="Margin" Value="10" />
</Style>
</Application.Resources>
我为测试创建了一个临时窗口:
<Window x:Class="Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VideoManager"
mc:Ignorable="d"
Title="Settings" Height="450" Width="800">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="145,46,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="145,121,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
就像我说的,从设计师的角度来看,一切看起来都和它应该的一样丑陋,但一旦建成,这些风格不知何故就没有被保留下来。
我还在一个新项目中尝试了相同的代码,在那里它确实起了作用
哪些设置可能会阻止按钮布局在生成模式下显示?我想XAML文件属性,例如
生成操作
和复制到输出目录
,这确实是问题所在。我完全忘记了,在某个时刻,我将Application.xaml build action设置为“none”,作为处理某些应用程序级事件的一个不明智的尝试的一部分。非常感谢你!很高兴为您提供帮助:)您可以将您的发现作为答案发布给未来的读者。