![](/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.