松散的XAML是依赖于引用的命名空间加载的.NET/CLR的版本?

Maj*_*Inc 5 .net c# wpf clr xaml

我刚刚阅读了WPF Unleashed,它提到按钮看起来会有所不同,具体取决于所使用的XMLNS.

所以我尝试了下面的内容并且它正确地敲响了.

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

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <StackPanel Height="40">
        <Button Content="Button1"/>
    </StackPanel>
</Page>
Run Code Online (Sandbox Code Playgroud)

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

<Page xmlns="http://schemas.microsoft.com/netfx/2009/xaml/presentation">
    <StackPanel Height="40">
        <Button Content="Button1"/>
    </StackPanel>
</Page>
Run Code Online (Sandbox Code Playgroud)

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

Yuv*_*kov 3

里面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)
Run Code Online (Sandbox Code Playgroud)

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