本文整理汇总了C#中ICSharpCode.WpfDesign.XamlDom.XamlObject类的典型用法代码示例。如果您正苦于以下问题:C# XamlObject类的具体用法?C# XamlObject怎么用?C# XamlObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XamlObject类属于ICSharpCode.WpfDesign.XamlDom命名空间,在下文中一共展示了XamlObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XamlObjectServiceProvider
/// <summary>
/// Creates a new XamlObjectServiceProvider instance.
/// </summary>
public XamlObjectServiceProvider(XamlObject obj)
{
if (obj == null)
throw new ArgumentNullException("obj");
XamlObject = obj;
Resolver = new XamlTypeResolverProvider(obj);
}
示例2: NameChanged
/// <summary>
/// Finds the XAML namescope for the specified object and uses it to unregister the old name and then register the new name.
/// </summary>
/// <param name="namedObject">The object where the name was changed.</param>
/// <param name="oldName">The old name.</param>
/// <param name="newName">The new name.</param>
public static void NameChanged(XamlObject namedObject, string oldName, string newName)
{
var obj = namedObject;
while (obj != null) {
var nameScope = obj.Instance as INameScope;
if (nameScope == null) {
var depObj = obj.Instance as DependencyObject;
if (depObj != null)
nameScope = NameScope.GetNameScope(depObj);
}
if (nameScope != null) {
if (oldName != null) {
try {
nameScope.UnregisterName(oldName);
} catch (Exception x) {
Debug.WriteLine(x.Message);
}
}
if (newName != null) {
nameScope.RegisterName(newName, namedObject.Instance);
try{
var prp = namedObject.ElementType.GetProperty(namedObject.RuntimeNameProperty);
if (prp != null)
prp.SetValue(namedObject.Instance, newName, null);
} catch (Exception x) {
Debug.WriteLine(x.Message);
}
}
break;
}
obj = obj.ParentObject;
}
}
示例3: XamlTypeResolverProvider
public XamlTypeResolverProvider(XamlObject containingObject)
{
if (containingObject == null)
throw new ArgumentNullException("containingObject");
this.document = containingObject.OwnerDocument;
this.containingObject = containingObject;
}
示例4: Print
/// <summary>
/// Generates XAML markup extension code for the object.
/// </summary>
public static string Print(XamlObject obj)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append(obj.GetNameForMarkupExtension());
bool first = true;
foreach (var property in obj.Properties) {
if (!property.IsSet) continue;
if (first)
sb.Append(" ");
else
sb.Append(", ");
first = false;
sb.Append(property.GetNameForMarkupExtension());
sb.Append("=");
var value = property.PropertyValue;
if (value is XamlTextValue) {
sb.Append((value as XamlTextValue).Text);
} else if (value is XamlObject) {
sb.Append(Print(value as XamlObject));
}
}
sb.Append("}");
return sb.ToString();
}
示例5: GetXaml
/// <summary>
/// Gets the Xaml string of the <paramref name="xamlObject"/>
/// </summary>
/// <param name="xamlObject">The object whose Xaml is requested.</param>
public static string GetXaml(XamlObject xamlObject)
{
if (xamlObject != null)
{
var nd = xamlObject.XmlElement.CloneNode(true);
var attLst = nd.Attributes.Cast<XmlAttribute>().ToDictionary(x => x.Name);
var ns = new List<XmlAttribute>();
var parentObject = xamlObject.ParentObject;
while (parentObject != null)
{
foreach (XmlAttribute attribute in parentObject.XmlElement.Attributes)
{
if (attribute.Name.StartsWith("xmlns:"))
{
if (!attLst.ContainsKey(attribute.Name))
{
nd.Attributes.Append((XmlAttribute)attribute.CloneNode(false));
attLst.Add(attribute.Name, attribute);
}
}
}
parentObject = parentObject.ParentObject;
}
return nd.OuterXml;
}
return null;
}
示例6: MarkupExtensionWrapper
/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="xamlObject">The <see cref="XamlObject"/> object that represents the markup extension.</param>
protected MarkupExtensionWrapper(XamlObject xamlObject)
{
if (xamlObject == null) {
throw new ArgumentNullException("xamlObject");
}
XamlObject = xamlObject;
}
示例7: CanPrint
/// <summary>
/// Gets whether shorthand XAML markup extension code can be generated for the object.
/// </summary>
public static bool CanPrint(XamlObject obj)
{
if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
return false;
}
return CanPrint(obj, false, GetNonMarkupExtensionParent(obj));
}
示例8: XamlProperty
internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo)
{
this.parentObject = parentObject;
this.propertyInfo = propertyInfo;
if (propertyInfo.IsCollection) {
isCollection = true;
collectionElements = new CollectionElementsCollection(this);
}
}
示例9: DummyTypeDescriptorContext
public DummyTypeDescriptorContext(XamlDocument document, XamlObject containingObject)
{
if (containingObject != null) {
if (containingObject.OwnerDocument != document)
throw new ArgumentException("Containing object must belong to the document!");
baseServiceProvider = containingObject.ServiceProvider;
} else {
baseServiceProvider = document.ServiceProvider;
}
}
示例10: Print
/// <summary>
/// Generates XAML markup extension code for the object.
/// </summary>
public static string Print(XamlObject obj)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append(obj.GetNameForMarkupExtension());
bool first = true;
var properties = obj.Properties.ToList();
if (obj.ElementType == typeof(Binding)){
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Path");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue, false);
properties.Remove(p);
first = false;
}
}
else if (obj.ElementType == typeof(Reference)){
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Name");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue, false);
properties.Remove(p);
first = false;
}
}
else if (obj.ElementType == typeof(StaticResourceExtension)){
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="ResourceKey");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue, false);
properties.Remove(p);
first = false;
}
}
foreach (var property in properties) {
if (!property.IsSet) continue;
if (first)
sb.Append(" ");
else
sb.Append(", ");
first = false;
sb.Append(property.GetNameForMarkupExtension());
sb.Append("=");
AppendPropertyValue(sb, property.PropertyValue, property.ReturnType == typeof(string));
}
sb.Append("}");
return sb.ToString();
}
示例11: GetTypeDescriptorContext
/// <summary>
/// Gets the type descriptor context used for type conversions.
/// </summary>
/// <param name="containingObject">The containing object, used when the
/// type descriptor context needs to resolve an XML namespace.</param>
internal ITypeDescriptorContext GetTypeDescriptorContext(XamlObject containingObject)
{
IServiceProvider serviceProvider;
if (containingObject != null) {
if (containingObject.OwnerDocument != this)
throw new ArgumentException("Containing object must belong to the document!");
serviceProvider = containingObject.ServiceProvider;
} else {
serviceProvider = this.ServiceProvider;
}
return new DummyTypeDescriptorContext(serviceProvider);
}
示例12: XamlProperty
internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo)
{
this.parentObject = parentObject;
this.propertyInfo = propertyInfo;
if (propertyInfo.IsCollection) {
isCollection = true;
collectionElements = new CollectionElementsCollection(this);
if (propertyInfo.Name.Equals(XamlConstants.ResourcesPropertyName, StringComparison.Ordinal) &&
propertyInfo.ReturnType == typeof(ResourceDictionary)) {
isResources = true;
}
}
}
示例13: Print
/// <summary>
/// Generates XAML markup extension code for the object.
/// </summary>
public static string Print(XamlObject obj)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append(obj.GetNameForMarkupExtension());
bool first = true;
foreach (var property in obj.Properties) {
if (!property.IsSet) continue;
if (first)
sb.Append(" ");
else
sb.Append(", ");
first = false;
sb.Append(property.GetNameForMarkupExtension());
sb.Append("=");
var value = property.PropertyValue;
var textValue = value as XamlTextValue;
if (textValue != null) {
string text = textValue.Text;
bool containsSpace = text.Contains(' ');
if(containsSpace) {
sb.Append('\'');
}
sb.Append(text.Replace("\\", "\\\\"));
if(containsSpace) {
sb.Append('\'');
}
} else if (value is XamlObject) {
sb.Append(Print(value as XamlObject));
}
}
sb.Append("}");
return sb.ToString();
}
示例14: CanPrint
/// <summary>
/// Gets whether shorthand XAML markup extension code can be generated for the object.
/// </summary>
public static bool CanPrint(XamlObject obj)
{
if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
return false;
}
foreach (var property in obj.Properties.Where((prop) => prop.IsSet))
{
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;
}
示例15: GetNameScopeFromObject
/// <summary>
/// Gets the XAML namescope for the specified object.
/// </summary>
/// <param name="obj">The object to get the XAML namescope for.</param>
/// <returns>A XAML namescope, as an <see cref="INameScope"/> instance.</returns>
public static INameScope GetNameScopeFromObject(XamlObject obj)
{
INameScope nameScope = null;
while (obj != null)
{
nameScope = obj.Instance as INameScope;
if (nameScope == null)
{
var xamlObj = obj.ParentObject != null ? obj.ParentObject : obj;
var depObj = xamlObj.Instance as DependencyObject;
if (depObj != null)
nameScope = NameScope.GetNameScope(depObj);
if (nameScope != null)
break;
}
obj = obj.ParentObject;
}
return nameScope;
}