|
|
@ -38,36 +38,7 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var property in obj.Properties.Where((prop) => prop.IsSet)) |
|
|
|
return CanPrint(obj, false, GetNonMarkupExtensionParent(obj)); |
|
|
|
{ |
|
|
|
|
|
|
|
var value = property.PropertyValue; |
|
|
|
|
|
|
|
if (value is XamlTextValue) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
XamlObject xamlObject = value as XamlObject; |
|
|
|
|
|
|
|
if (xamlObject == null || !xamlObject.IsMarkupExtension) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
var staticResource = xamlObject.Instance as System.Windows.StaticResourceExtension; |
|
|
|
|
|
|
|
if (staticResource != null && |
|
|
|
|
|
|
|
staticResource.ResourceKey != null) { |
|
|
|
|
|
|
|
XamlObject parent = GetNonMarkupExtensionParent(xamlObject); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parent != null) { |
|
|
|
|
|
|
|
var parentLocalResource = parent.ServiceProvider.Resolver.FindLocalResource(staticResource.ResourceKey); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If resource with the specified key is declared locally on the same object as the StaticResource is being used the markup extension
|
|
|
|
|
|
|
|
// must be printed as element to find the resource, otherwise it will search from parent-parent and find none or another resource.
|
|
|
|
|
|
|
|
if (parentLocalResource != null) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -115,6 +86,28 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
return sb.ToString(); |
|
|
|
return sb.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool CanPrint(XamlObject obj, bool isNested, XamlObject nonMarkupExtensionParent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ((isNested || obj.ParentObject == nonMarkupExtensionParent) && IsStaticResourceThatReferencesLocalResource(obj, nonMarkupExtensionParent)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var property in obj.Properties.Where((prop) => prop.IsSet)) { |
|
|
|
|
|
|
|
var value = property.PropertyValue; |
|
|
|
|
|
|
|
if (value is XamlTextValue) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
var xamlObject = value as XamlObject; |
|
|
|
|
|
|
|
if (xamlObject == null || !xamlObject.IsMarkupExtension) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return CanPrint(xamlObject, true, nonMarkupExtensionParent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static XamlObject GetNonMarkupExtensionParent(XamlObject markupExtensionObject) |
|
|
|
private static XamlObject GetNonMarkupExtensionParent(XamlObject markupExtensionObject) |
|
|
|
{ |
|
|
|
{ |
|
|
|
System.Diagnostics.Debug.Assert(markupExtensionObject.IsMarkupExtension); |
|
|
|
System.Diagnostics.Debug.Assert(markupExtensionObject.IsMarkupExtension); |
|
|
@ -125,5 +118,21 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
} |
|
|
|
} |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool IsStaticResourceThatReferencesLocalResource(XamlObject obj, XamlObject nonMarkupExtensionParent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var staticResource = obj.Instance as System.Windows.StaticResourceExtension; |
|
|
|
|
|
|
|
if (staticResource != null && staticResource.ResourceKey != null && nonMarkupExtensionParent != null) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parentLocalResource = nonMarkupExtensionParent.ServiceProvider.Resolver.FindLocalResource(staticResource.ResourceKey); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If resource with the specified key is declared locally on the same object as the StaticResource is being used the markup extension
|
|
|
|
|
|
|
|
// must be printed as element to find the resource, otherwise it will search from parent-parent and find none or another resource.
|
|
|
|
|
|
|
|
if (parentLocalResource != null) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|