![](/img/trans.png)
[英]Global styles from App.xaml applying in designer but not at runtime as of recently
[英]Styles form app.xaml not found by the designer
我刚刚注意到,我的xaml编辑器看不到App.xaml中定义的样式。
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Windows\MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Assets/Themes/ShinyBlue.xaml"/>
</ResourceDictionary.MergedDictionaries>
// this one gets a warning that's never used, though it is
<LinearGradientBrush x:Key="backgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{StaticResource NormalBrushGradient3}" Offset="0.1" />
<GradientStop Color="{StaticResource NormalBrushGradient1}" Offset="0.4" />
</LinearGradientBrush>
每次调用此类样式都带有下划线,并且设计师都不加载两种样式(所有东西都是白色的)。 当我运行该应用程序时,一切看起来都很好-正在加载样式。
最近,我将入口点更改为我的应用程序:
public partial class App : Application
{
[System.STAThreadAttribute()]
public static int Main(string[] args)
{
var dirsToCreate = new[]
{
Settings.Default.PhotosDirectory
};
foreach (var dir in dirsToCreate)
{
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
}
App app = new App();
app.InitializeComponent();
app.Run();
return 0;
}
我怀疑,但不能确定此更改的入口点可能与此有关(我将MainWinow的build动作更改为“ Page”)。
任何想法怎么回事以及如何解决?
由于更改了入口点,您是否将app.xaml中的“ StartupUri”属性更改为要启动的新窗口?
app.xaml文件中的x:Class属性是什么,startupwindow.xaml文件中的x:Class属性是什么?
您是否尝试过将样式引用为DynamicResource而不是StaticResource? DynamicResource不会在编译时加载样式,而是在运行时加载样式。 编辑时,您不会在“设计”窗口中看到已应用的样式,但是在您运行应用程序时将应用样式。 这可能不是解决此问题的最佳方法,但是我过去只是为了克服一些愚蠢的小障碍而这样做。 就我个人而言,我从来没有使用过设计器窗口,我只是用XAML编写了我的UI,所以这对我来说并不是真正的问题。
试试看,让我知道其中是否有一个适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.