样式形成app.xaml,设计师找不到

时间:2022-01-21 17:26:32

I've just noticed than my xaml editor cannot see styles defined in App.xaml.

我刚注意到,我的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>

Every call to such a style is underlined and neither of the styles is loaded by designer (everything is back and white). When I run the app it all looks well - style are being loaded.

每个对这种风格的调用都有下划线,设计师都没有加载任何样式(一切都是背面和白色)。当我运行应用程序时,它看起来都很好 - 正在加载样式。

Recently I changed the entry point to my app:

最近我改变了我的应用程序的入口点:

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;
    }

I suspect, but cannot be sure that this changed entry point may have something to do with that (I changed MainWinow's build action to 'Page').

我怀疑,但不能确定这个改变的入口点可能与此有关(我将MainWinow的构建操作改为'Page')。

Any ideas what's going on and how to fix that?

任何想法发生了什么以及如何解决这个问题?

1 个解决方案

#1


0  

  1. Since you changed your entry point, did you change your "StartupUri" attribute in the app.xaml to the new window you want to launch?

    由于您更改了入口点,是否将app.xaml中的“StartupUri”属性更改为要启动的新窗口?

  2. What is your x:Class attribute in your app.xaml file and what is your x:Class attribute in your startupwindow.xaml file?

    app.xaml文件中的x:Class属性是什么?startupwindow.xaml文件中的x:Class属性是什么?

  3. Have you tried referencing your styles as a DynamicResource instead of a StaticResource? A DynamicResource won't load your styles at compile time, it will load them at run-time. You won't see your styles applied in the Design window when editing but the styles will be applied when you run your application. This may not be the best way to fix this problem, but I have done it in the past just to get over some stupid little hurdles. Personally, I never use the designer window, I just write my UI all in XAML so this wasn't really an issue for me.

    您是否尝试将样式引用为DynamicResource而不是StaticResource? DynamicResource不会在编译时加载样式,它会在运行时加载它们。编辑时,您不会在“设计”窗口中看到样式,但在运行应用程序时将应用样式。这可能不是解决这个问题的最佳方法,但我过去只是为了克服一些愚蠢的小障碍。就个人而言,我从不使用设计器窗口,我只是在XAML中编写我的UI,所以这对我来说不是一个问题。

Give these a try and let me know if any of them work for you.

尝试一下,让我知道他们中的任何一个是否适合你。

#1


0  

  1. Since you changed your entry point, did you change your "StartupUri" attribute in the app.xaml to the new window you want to launch?

    由于您更改了入口点,是否将app.xaml中的“StartupUri”属性更改为要启动的新窗口?

  2. What is your x:Class attribute in your app.xaml file and what is your x:Class attribute in your startupwindow.xaml file?

    app.xaml文件中的x:Class属性是什么?startupwindow.xaml文件中的x:Class属性是什么?

  3. Have you tried referencing your styles as a DynamicResource instead of a StaticResource? A DynamicResource won't load your styles at compile time, it will load them at run-time. You won't see your styles applied in the Design window when editing but the styles will be applied when you run your application. This may not be the best way to fix this problem, but I have done it in the past just to get over some stupid little hurdles. Personally, I never use the designer window, I just write my UI all in XAML so this wasn't really an issue for me.

    您是否尝试将样式引用为DynamicResource而不是StaticResource? DynamicResource不会在编译时加载样式,它会在运行时加载它们。编辑时,您不会在“设计”窗口中看到样式,但在运行应用程序时将应用样式。这可能不是解决这个问题的最佳方法,但我过去只是为了克服一些愚蠢的小障碍。就个人而言,我从不使用设计器窗口,我只是在XAML中编写我的UI,所以这对我来说不是一个问题。

Give these a try and let me know if any of them work for you.

尝试一下,让我知道他们中的任何一个是否适合你。