【问题标题】:How does the default xml namespace work in XAML?默认的 xml 命名空间在 XAML 中是如何工作的?
【发布时间】:2010-03-25 16:53:05
【问题描述】:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

这个 url 如何映射到 .NET 命名空间?您能否举例说明如何为自定义 .NET 类/命名空间做同样的事情?它是必须在命名空间本身上定义的属性吗?

或者是问题还是使用 C# 别名?:

using alias = FullNamespace

【问题讨论】:

    标签: c# .net wpf xaml


    【解决方案1】:

    映射是使用XmlnsDefinition 属性完成的。例如:

    [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Data")]
    [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows")]
    [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls.Primitives")]
    [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media.Animation")]
    [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Input")]
    

    (使用 Reflector 提取的 PresentationFramework.dll 中的代码)

    【讨论】:

    • 是的,但我不建议这样做,因为它可能会导致您的类与标准 WPF 命名空间中的类之间发生冲突
    猜你喜欢
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 2021-10-10
    相关资源
    最近更新 更多