iNKORE-NET / UI.WPF.Modern

Modern (Fluent 2) styles and controls for your WPF applications
https://docs.inkore.net/ui-wpf-modern
GNU Lesser General Public License v2.1
332 stars 29 forks source link

System.Windows.Markup.XamlParseException:““初始化“Inkore.UI.WPF.Modern.ThemeResources”时引发了异常。”,行号为“10”,行位置为“18”。 #17

Closed BoyFaceGirl closed 10 months ago

BoyFaceGirl commented 10 months ago

我wpf用的.net core 7如下图

image

Inkore.UI.WPF.Modern 版本为0.918如下图

image

这是mainWindow 的代码

image

这是报错信息

image

这是报错的堆栈信息

System.Windows.Markup.XamlParseException HResult=0x80131501 Message=“初始化“Inkore.UI.WPF.Modern.ThemeResources”时引发了异常。”,行号为“10”,行位置为“18”。 Source=PresentationFramework StackTrace: 在 System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) 在 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 在 System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) 在 System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) 在 System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) 在 UI.WPF.Modern.App.InitializeComponent() 在 E:\Student\DotNet\WinUI\UI.WPF.Modern\Win11StyleWpf\UI.WPF.Modern\App.xaml 中: 第 1 行 在 UI.WPF.Modern.App.Main()

此异常最初是在此调用堆栈中引发的: [外部代码]

内部异常 1: TypeInitializationException: The type initializer for 'Inkore.UI.WPF.Modern.ThemeManager' threw an exception.

内部异常 2: TypeInitializationException: The type initializer for 'Inkore.UI.WPF.Modern.ColorsHelper' threw an exception.

内部异常 3: PlatformNotSupportedException: Operation is not supported on this platform. (0x80131539)

这是我测试用的源代码

Win11StyleWpf.zip

NotYoojun commented 10 months ago

你好!感谢使用,很抱歉你遇到了这样的问题。

请尝试将框架改成 net6.0-windows10.0.18362.0 试试,看能不能解决你的问题。

image

谢谢!

NotYoojun commented 10 months ago

另外,我帮你改了下 MainWindow.xaml 的代码,好让它看起来更好看:

<Window x:Class="UI.WPF.Modern.MainWindow"
        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:UI.WPF.Modern"
        mc:Ignorable="d"
        xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
        Title="MainWindow" Height="450" Width="800"
        ui:WindowHelper.SystemBackdropType="Mica" ui:WindowHelper.UseModernWindowStyle="True" ui:TitleBar.Height="36">
    <Grid>
        <ui:NavigationView IsPaneOpen="False">
            <ui:NavigationView.MenuItems>

                <ui:NavigationViewItem Content="Home">
                    <ui:NavigationViewItem.Icon>
                        <ui:FontIcon Glyph="{x:Static ui:SegoeIcons.Home}"/>
                    </ui:NavigationViewItem.Icon>
                </ui:NavigationViewItem>
                <ui:NavigationViewItem Content="Shop">
                    <ui:NavigationViewItem.Icon>
                        <ui:FontIcon Glyph="{x:Static ui:SegoeIcons.Shop}"/>
                    </ui:NavigationViewItem.Icon>
                </ui:NavigationViewItem>

            </ui:NavigationView.MenuItems>
            <ui:NavigationView.FooterMenuItems>

                <ui:NavigationViewItem Content="Settings">
                    <ui:NavigationViewItem.Icon>
                        <ui:FontIcon Glyph="{x:Static ui:SegoeIcons.Settings}"/>
                    </ui:NavigationViewItem.Icon>
                </ui:NavigationViewItem>

            </ui:NavigationView.FooterMenuItems>
        </ui:NavigationView>
    </Grid>
</Window>

它看起来应该是这样:

image
NotYoojun commented 10 months ago

如果问题解决就可以关闭issue了,祝你生活愉快!

BoyFaceGirl commented 10 months ago

如果问题解决就可以关闭issue了,祝你生活愉快!

限定windows 版本的原因是什么?是因为 mic特效么?如果我不想限定windows版本有没有什么配置可以进行选择?

NotYoojun commented 10 months ago

因为里面有一些和winrt的交互,比如主题颜色,mica之类的,所以目标操作系统必须是这个。 不过你可以把最低操作系统(受支持的os版本)改成7.0,这样在win7和8上也可以运行。

BoyFaceGirl commented 10 months ago

因为里面有一些和winrt的交互,比如主题颜色,mica之类的,所以目标操作系统必须是这个。 不过你可以把最低操作系统(受支持的os版本)改成7.0,这样在win7和8上也可以运行。

额,真的是学无止尽了,wpf 和winrt怎么交互我是真的一点都不懂也不会啊,感谢楼主的开源奉献,为表敬意,小小的支持一下,记住我 github 账号叫 boyfacegirl,刚刚想捐点,但是你给的网站打不开注册不上,建议把收款码铁道 read.md 文件里

NotYoojun commented 10 months ago

感谢支持!这是我的赞助页面: https://inkore.net/about/members/notyoojun#sponsor