WPF - globally add xaml namespace declaration

后端 未结 1 571
故里飘歌
故里飘歌 2021-02-13 10:09

I have quite a huge WPF application with a lot of XAML files. Every single XAML file has from 5 to 10 clr to xml namespace mappings xmlns:abc=\"clr-namespace:Abcdef\"

1条回答
  •  無奈伤痛
    2021-02-13 10:39

    There is no way to define them globally across files. This is a limitation of XML; XAML is a subset of it.

    However you can clean them up a bit using XmlnsDefinition

    See this article: http://zachbonham.blogspot.com/2010/04/organize-xaml-namespace-declarations.html

    If you started with this XAML:

    
      
    
    

    And added these XmlnsDefinition attributes:

    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.InfoBar.Views")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.RoleGroupPicker.Views")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.BetterPopup")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.TextEditor")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.Converters")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.Documents")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.SplashScreen")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.TemplateSelector")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.ModalDialog")]
    [assembly: XmlnsDefinition("urn:marykay-samportal-common-ui", "MaryKay.SamPortal.Common.UI.ConsultantSearch.Views")]
    // etc...
    

    You could end up with this XAML instead:

    
      
    
    

    0 讨论(0)
提交回复
热议问题