2017-11-22 10 views
2

WPF 응용 프로그램에서 XmlnsDefinitions를 만들어 다른 어셈블리의 여러 네임 스페이스를 하나의 참조로 매핑 할 수 있습니다.WPF XAML 기본 네임 스페이스 정의를 병합

당신은 예를 들어, 마이크로 소프트의 기본 XmlnsDefinition에 자신의 네임 스페이스를 매핑하는 것을 활용할 수 있습니다

[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "MyLibrary.MyControls")] 

이 방법은, 당신도 XAML에 네임 스페이스에 대한 참조를 추가 할 필요가 없습니다 왜냐하면 그들은 이미 기본 "xmlns"에 매핑되어 있기 때문입니다.

<MyControl /> 

내 질문이입니다 : 내가 기본 Microsoft 네임 스페이스가 병합 할 수 나는 "MyControl"라는 컨트롤이 있다면

그래서, 나는 (모든 네임 스페이스 또는 접두사없이)과 같이 사용할 수 있습니다 하나 하나로?

예 : "xmlns : x"네임 스페이스를 "xmlns"에 병합하여 제거하고자합니다. "http://schemas.microsoft.com/winfx/2006/xaml"의 모든 네임 스페이스를 "http://schemas.microsoft.com/winfx/2006/xaml/presentation"으로 참조해야합니다. 이처럼

:

[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System...")] 
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System...")] 
... 

그래서 나는이를 설정할 수 있습니다 :

<Window x:Class="MyProject.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    > 

을이 속으로 :

<Window Class="MyProject.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    > 
+0

중복 : https://stackoverflow.com/questions/47427705/c-sharp-xml-writer-format-amazonenvelope-for-au-scratchpad#comment81843968_47427705. 문자열 innerxml = "xsi : noNamespaceSchemaLocation = \"amzn-envelope.xsd \ "xmlns : xsi = \"w3.org/2001/XMLSchema-instance \ ""; using (var writer = XmlWriter.Create (stream, settings)) {writer.WriteStartElement ("AmazonEnvelope"); writer.WriteRaw (innerxml); writer.WriteEndElement(); } – jdweng

+0

그 질문은 내 것과 관련이 없습니다. –

답변

3

이미 존재하는 것처럼 네임 스페이스 매핑을 기존 무시할 수 없습니다 표준 어셈블리에서는 모든 .NET 네임 스페이스를 자신의 XML 네임 스페이스에 병합 할 수 있습니다. 그것은 일 (나는 시도하지 않은) 수

[assembly: XmlnsDefinition("urn:foobar", "System.Windows.Controls")] 
[assembly: XmlnsDefinition("urn:foobar", "System.Windows.Documents")] 
[assembly: XmlnsDefinition("urn:foobar", "System.Windows.Shapes")] 
// ... 
[assembly: XmlnsDefinition("urn:foobar", "FoobarLibrary.Controls")] 
// ... 

: 이것처럼. 귀하의 XAML은 다음과 같이 표시됩니다 : 당신이 x 네임 스페이스를 제거 할 수

<Window x:Class="FoobarProject.MainWindow" 
    xmlns="urn:foobar" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

참고 :

그것은 .NET 네임 스페이스에 매핑되지 않은
  1. , 순수한 XML 네임 스페이스와의 일부 XAML 언어.

  2. 이렇게하면 충돌이 발생합니다 (x:NameName).

충돌과 관련하여이 같은 네임 스페이스를 병합하면 문제가 발생합니다. 이 네임 스페이스가 해결하도록 설계된 이름 충돌이 발생할 가능성이 큽니다.

+0

벙어리 넷 라이브러리는 항상 기본 네임 스페이스를 마지막 항목으로 원합니다. – jdweng

+0

"기존 네임 스페이스 매핑이 이미 표준 어셈블리에 있으므로 무시할 수 없습니다."라고 생각해야합니다. –