gpt4 book ai didi

c# - 松散的 XAML 是根据引用的命名空间加载的 .NET/CLR 版本吗?

转载 作者:太空狗 更新时间:2023-10-29 23:31:00 25 4
gpt4 key购买 nike

我刚刚阅读了 WPF Unleashed,其中提到根据所使用的 XMLNS,按钮看起来会有所不同。

所以我尝试了下面的方法,它成功了。

在此代码中加载了光泽按钮。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel Height="40">
<Button Content="Button1"/>
</StackPanel>
</Page>

在此代码中加载了非光泽按钮。

<Page xmlns="http://schemas.microsoft.com/netfx/2009/xaml/presentation">
<StackPanel Height="40">
<Button Content="Button1"/>
</StackPanel>
</Page>

我只是想弄清楚到底发生了什么?PresentationHost.exe 在看到 ../netfx/2009/... 命名空间时加载 4.0 CLR 是否只是硬编码?

最佳答案

PresentationFramework.dll 中有一个使用 XmlnsDefinitionAttribute 的映射.

当编译器命中命名空间时,它会查找与目标 XAML 命名空间匹配的指定 dll:

[System.Windows.Markup.XmlnsDefinitionAttribute("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Media.Animation"),
System.Runtime.CompilerServices.CompilationRelaxationsAttribute(8)

如果它命中 winfx/2006,它将查找 XAML 2006 对应的 dll。如果它命中 netfx/2009,它将查找 XAML 2009 dll。

关于c# - 松散的 XAML 是根据引用的命名空间加载的 .NET/CLR 版本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25491526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com