@ -24,7 +24,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -24,7 +24,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlTypeFinder _ typeFinder ;
int namespacePrefixCounter ;
int namespacePrefixCounter ;
internal XmlDocument XmlDocument {
get { return _ xmlDoc ; }
@ -173,14 +173,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -173,14 +173,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
return new XamlTextValue ( this , c . ConvertToInvariantString ( ctx , instance ) ) ;
}
string ns = GetNamespaceFor ( elementType ) ;
string prefix = GetPrefixForNamespace ( ns ) ;
XmlElement xml = _ xmlDoc . CreateElement ( prefix , elementType . Name , ns ) ;
string ns = GetNamespaceFor ( elementType ) ;
string prefix = GetPrefixForNamespace ( ns ) ;
XmlElement xml = _ xmlDoc . CreateElement ( prefix , elementType . Name , ns ) ;
if ( hasStringConverter & & XamlObject . GetContentPropertyName ( elementType ) ! = null ) {
xml . InnerText = c . ConvertToInvariantString ( instance ) ;
} else if ( instance is Brush ) { //Todo: this is a hacky fix, because Brush Editor don't edit Design Items and so we have no XML, only the Brush Object and we need to Parse the Brush to XAML!
} else if ( instance is Brush ) { // TODO: this is a hacky fix, because Brush Editor doesn't
// edit Design Items and so we have no XML, only the Brush
// object and we need to parse the Brush to XAML!
var s = new MemoryStream ( ) ;
XamlWriter . Save ( instance , s ) ;
s . Seek ( 0 , SeekOrigin . Begin ) ;
@ -212,48 +214,48 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -212,48 +214,48 @@ namespace ICSharpCode.WpfDesign.XamlDom
return _ typeFinder . GetXmlNamespaceFor ( type . Assembly , type . Namespace ) ;
}
internal string GetPrefixForNamespace ( string @namespace )
{
if ( @namespace = = XamlConstants . PresentationNamespace )
{
return null ;
}
internal string GetPrefixForNamespace ( string @namespace )
{
if ( @namespace = = XamlConstants . PresentationNamespace )
{
return null ;
}
string prefix = _ xmlDoc . DocumentElement . GetPrefixOfNamespace ( @namespace ) ;
string prefix = _ xmlDoc . DocumentElement . GetPrefixOfNamespace ( @namespace ) ;
if ( String . IsNullOrEmpty ( prefix ) )
{
prefix = _ typeFinder . GetPrefixForXmlNamespace ( @namespace ) ;
if ( String . IsNullOrEmpty ( prefix ) )
{
prefix = _ typeFinder . GetPrefixForXmlNamespace ( @namespace ) ;
string existingNamespaceForPrefix = null ;
if ( ! String . IsNullOrEmpty ( prefix ) )
{
existingNamespaceForPrefix = _ xmlDoc . DocumentElement . GetNamespaceOfPrefix ( prefix ) ;
}
string existingNamespaceForPrefix = null ;
if ( ! String . IsNullOrEmpty ( prefix ) )
{
existingNamespaceForPrefix = _ xmlDoc . DocumentElement . GetNamespaceOfPrefix ( prefix ) ;
}
if ( String . IsNullOrEmpty ( prefix ) | |
! String . IsNullOrEmpty ( existingNamespaceForPrefix ) & &
existingNamespaceForPrefix ! = @namespace )
{
do
{
prefix = "Controls" + namespacePrefixCounter + + ;
} while ( ! String . IsNullOrEmpty ( _ xmlDoc . DocumentElement . GetNamespaceOfPrefix ( prefix ) ) ) ;
}
if ( String . IsNullOrEmpty ( prefix ) | |
! String . IsNullOrEmpty ( existingNamespaceForPrefix ) & &
existingNamespaceForPrefix ! = @namespace )
{
do
{
prefix = "Controls" + namespacePrefixCounter + + ;
} while ( ! String . IsNullOrEmpty ( _ xmlDoc . DocumentElement . GetNamespaceOfPrefix ( prefix ) ) ) ;
}
string xmlnsPrefix = _ xmlDoc . DocumentElement . GetPrefixOfNamespace ( XamlConstants . XmlnsNamespace ) ;
System . Diagnostics . Debug . Assert ( ! String . IsNullOrEmpty ( xmlnsPrefix ) ) ;
string xmlnsPrefix = _ xmlDoc . DocumentElement . GetPrefixOfNamespace ( XamlConstants . XmlnsNamespace ) ;
System . Diagnostics . Debug . Assert ( ! String . IsNullOrEmpty ( xmlnsPrefix ) ) ;
_ xmlDoc . DocumentElement . SetAttribute ( xmlnsPrefix + ":" + prefix , @namespace ) ;
if ( @namespace = = XamlConstants . DesignTimeNamespace )
{
var ignorableProp = new XamlProperty ( this . _ rootElement , new XamlDependencyPropertyInfo ( MarkupCompatibilityProperties . IgnorableProperty , true ) ) ;
ignorableProp . SetAttribute ( prefix ) ;
}
}
_ xmlDoc . DocumentElement . SetAttribute ( xmlnsPrefix + ":" + prefix , @namespace ) ;
if ( @namespace = = XamlConstants . DesignTimeNamespace )
{
var ignorableProp = new XamlProperty ( this . _ rootElement , new XamlDependencyPropertyInfo ( MarkupCompatibilityProperties . IgnorableProperty , true ) ) ;
ignorableProp . SetAttribute ( prefix ) ;
}
}
return prefix ;
}
return prefix ;
}
}
}