private void AddScopeElements(INameScope scope, ElementAccessor[] elements, ref bool duplicateElements, bool allowDuplicates) { for (int i = 0; i < elements.Length; i++) { this.AddScopeElement(scope, elements[i], ref duplicateElements, allowDuplicates); } }
public void Remove(FrameworkElement target, INameScope nameScope, object layerOwner) { if (Storyboard != null) { Storyboard.Remove(target, nameScope, layerOwner); } }
public Timer( NodeGCType gcType, INodeScope parentNodeScope, INameScope parentNameScope, string initialBasicName ) : base(gcType, parentNodeScope, parentNameScope, initialBasicName) { Debug.Assert(gcType == s_gcTypeOfAllInstances); }
public InitializeContext(object target, InitializeContext parentContext, INameScope nameScope, FrameworkElement templatedParent, BaseValueSource valueSource) { this.Target = target; this.ParentContext = parentContext; this.NameScope = nameScope; this.TemplatedParent = templatedParent; this.ValueSource = valueSource; this.Root = parentContext != null && parentContext.Root != null ? parentContext.Root : Target; }
private static void AddUniqueAccessor(INameScope scope, Accessor accessor) { Accessor accessor2 = (Accessor) scope[accessor.Name, accessor.Namespace]; if (accessor2 != null) { if (accessor is ElementAccessor) { throw new InvalidOperationException(Res.GetString("XmlDuplicateElementName", new object[] { accessor2.Name, accessor2.Namespace })); } throw new InvalidOperationException(Res.GetString("XmlDuplicateAttributeName", new object[] { accessor2.Name, accessor2.Namespace })); } scope[accessor.Name, accessor.Namespace] = accessor; }
private static void AddUniqueAccessor(MemberMapping member, INameScope elements, INameScope attributes, bool isSequence) { if (member.Attribute != null) { AddUniqueAccessor(attributes, member.Attribute); } else if ((!isSequence && (member.Elements != null)) && (member.Elements.Length > 0)) { for (int i = 0; i < member.Elements.Length; i++) { AddUniqueAccessor(elements, member.Elements[i]); } } }
public void Begin(FrameworkElement containingObject, INameScope nameScope = null, HandoffBehavior handoffBehavior = HandoffBehavior.SnapshotAndReplace, object layerOwner = null) { Stop(containingObject); TimelineClock clock = CreateClock(); clock.Begin(((IAnimatable)containingObject).RootClock); clocks[containingObject] = clock; ListDictionary<TargetKey, AnimationTimelineClock> targets = GetAnimationClocksTargets(clock, containingObject, nameScope ?? NameScope.GetContainingNameScope(containingObject)); foreach (TargetKey target in targets.GetKeys()) { target.Target.ApplyAnimationClocks(target.TargetProperty, targets.GetValues(target), handoffBehavior, layerOwner); } }
private void AddScopeElement(INameScope scope, ElementAccessor element, ref bool duplicateElements, bool allowDuplicates) { if (scope != null) { ElementAccessor accessor = (ElementAccessor) scope[element.Name, element.Namespace]; if (accessor != null) { if (!allowDuplicates) { throw new InvalidOperationException(Res.GetString("XmlDuplicateElementInScope", new object[] { element.Name, element.Namespace })); } if (accessor.Mapping.TypeDesc != element.Mapping.TypeDesc) { throw new InvalidOperationException(Res.GetString("XmlDuplicateElementInScope1", new object[] { element.Name, element.Namespace })); } duplicateElements = true; } else { scope[element.Name, element.Namespace] = element; } } }
static void AddUniqueAccessor(INameScope scope, Accessor accessor) { Accessor existing = (Accessor)scope[accessor.Name, accessor.Namespace]; if (existing != null) { if (accessor is ElementAccessor) { throw new InvalidOperationException(Res.GetString(Res.XmlDuplicateElementName, existing.Name, existing.Namespace)); } else { #if DEBUG if (!(accessor is AttributeAccessor)) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Bad accessor type " + accessor.GetType().FullName)); #endif throw new InvalidOperationException(Res.GetString(Res.XmlDuplicateAttributeName, existing.Name, existing.Namespace)); } } else { scope[accessor.Name, accessor.Namespace] = accessor; } }
protected override void OnTemplateApplied(INameScope nameScope) { OnTemplateAppliedCalled = true; }
/// <summary> /// Recursively walks the clock tree and determine the target object /// and property for each clock in the tree. /// </summary> /// <remarks> /// The currently active object and property path are passed in as parameters, /// they will be used unless a target/property specification exists on /// the Timeline object corresponding to the current clock. (So that the /// leaf-most reference wins.) /// /// The active object and property parameters may be null if they have /// never been specified. If we reach a leaf node clock and a needed attribute /// is still null, it is an error condition. Otherwise we keep hoping they'll be found. /// </remarks> private void ClockTreeWalkRecursive( Clock currentClock, /* No two calls will have the same currentClock */ DependencyObject containingObject, /* Remains the same through all the recursive calls */ INameScope nameScope, /* Remains the same through all the recursive calls */ DependencyObject parentObject, string parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, /* Remains the same through all the recursive calls */ HybridDictionary clockMappings, Int64 layer /* Remains the same through all the recursive calls */) { Timeline currentTimeline = currentClock.Timeline; DependencyObject targetObject = parentObject; string currentObjectName = parentObjectName; PropertyPath currentPropertyPath = parentPropertyPath; // If we have target object/property information, use it instead of the // parent's information. string nameString = (string)currentTimeline.GetValue(TargetNameProperty); if( nameString != null ) { if( nameScope is Style ) { // We are inside a Style - we don't let people target anything. // They're only allowed to modify the Styled object, which is // already the implicit target. throw new InvalidOperationException(SR.Get(SRID.Storyboard_TargetNameNotAllowedInStyle, nameString)); } currentObjectName = nameString; } // The TargetProperty trumps the TargetName property. DependencyObject localTargetObject = (DependencyObject) currentTimeline.GetValue(TargetProperty); if( localTargetObject != null ) { targetObject = localTargetObject; currentObjectName = null; } PropertyPath propertyPath = (PropertyPath)currentTimeline.GetValue(TargetPropertyProperty); if( propertyPath != null ) { currentPropertyPath = propertyPath; } // Now see if the current clock is an animation clock if( currentClock is AnimationClock ) { DependencyProperty targetProperty = null; AnimationClock animationClock = (AnimationClock)currentClock; if( targetObject == null ) { // Resolve the target object name. If no name specified, use the // containing object. if( currentObjectName != null ) { DependencyObject mentor = Helper.FindMentor(containingObject); targetObject = ResolveTargetName(currentObjectName, nameScope, mentor); } else { // The containing object must be either an FE or FCE. // (Not a Storyboard, as used for "shared clocks" mode.) targetObject = containingObject as FrameworkElement; if(targetObject == null) { targetObject = containingObject as FrameworkContentElement; } if( targetObject == null ) { // The containing object is not an FE or FCE. throw new InvalidOperationException(SR.Get(SRID.Storyboard_NoTarget, currentTimeline.GetType().ToString() )); } } } // See if we have a property name to use. if( currentPropertyPath == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_TargetPropertyRequired, currentTimeline.GetType().ToString() )); } // A property name can be a straightforward property name (like "Angle") // but may be a more complex multi-step property path. The two cases // are handled differently. using(currentPropertyPath.SetContext(targetObject)) { if( currentPropertyPath.Length < 1 ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_PropertyPathEmpty)); } VerifyPathIsAnimatable(currentPropertyPath); if( currentPropertyPath.Length == 1 ) { // We have a simple single-step property. targetProperty = currentPropertyPath.GetAccessor(0) as DependencyProperty; if( targetProperty == null ) { // Unfortunately it's not a DependencyProperty. throw new InvalidOperationException(SR.Get(SRID.Storyboard_PropertyPathMustPointToDependencyProperty, currentPropertyPath.Path )); } VerifyAnimationIsValid(targetProperty, animationClock); ObjectPropertyPair animatedTarget = new ObjectPropertyPair(targetObject, targetProperty); UpdateMappings(clockMappings, animatedTarget, animationClock); } else // path.Length > 1 { // This is a multi-step property path that requires more extensive // setup. ProcessComplexPath(clockMappings, targetObject, currentPropertyPath, animationClock, handoffBehavior, layer); } } } else if ( currentClock is MediaClock ) // Not an animation clock - maybe a media clock? { // Yes it's a media clock. Try to find the corresponding object and // apply the clock to that object. ApplyMediaClock(nameScope, containingObject, targetObject, currentObjectName, (MediaClock) currentClock); } else { // None of the types we recognize as leaf node clock types - // recursively process child clocks. ClockGroup currentClockGroup = currentClock as ClockGroup; if (currentClockGroup != null) { ClockCollection childrenClocks = currentClockGroup.Children; for( int i = 0; i < childrenClocks.Count; i++ ) { ClockTreeWalkRecursive( childrenClocks[i], containingObject, nameScope, targetObject, currentObjectName, currentPropertyPath, handoffBehavior, clockMappings, layer); } } } }
protected BeginStoryboard GetBeginStoryboard(FrameworkElement target) { INameScope nameScope = NameScope.GetContainingNameScope(target); return(nameScope != null?nameScope.FindName(BeginStoryboardName) as BeginStoryboard : null); }
/// <summary> /// Initializes a new instance of the <see cref="Control"/> class. /// </summary> public Control() { _nameScope = this as INameScope; }
/// <summary> /// Called when the control's template is applied. /// </summary> /// <param name="nameScope">The template name scope.</param> protected virtual void OnTemplateApplied(INameScope nameScope) { }
private void Initialize(XamlSchemaContext schemaContext, XamlSavedContext savedContext, XamlObjectWriterSettings settings) { this._inDispose = false; if (schemaContext == null) { throw new ArgumentNullException("schemaContext"); } if ((savedContext != null) && (schemaContext != savedContext.SchemaContext)) { throw new ArgumentException(System.Xaml.SR.Get("SavedContextSchemaContextMismatch"), "schemaContext"); } if (settings != null) { this._afterBeginInitHandler = settings.AfterBeginInitHandler; this._beforePropertiesHandler = settings.BeforePropertiesHandler; this._afterPropertiesHandler = settings.AfterPropertiesHandler; this._afterEndInitHandler = settings.AfterEndInitHandler; this._xamlSetValueHandler = settings.XamlSetValueHandler; this._rootObjectInstance = settings.RootObjectInstance; this._skipDuplicatePropertyCheck = settings.SkipDuplicatePropertyCheck; this._skipProvideValueOnRoot = settings.SkipProvideValueOnRoot; this._preferUnconvertedDictionaryKeys = settings.PreferUnconvertedDictionaryKeys; } INameScope rootNameScope = (settings != null) ? settings.ExternalNameScope : null; XamlRuntime runtime = this.CreateRuntime(settings, schemaContext); if (savedContext != null) { this._context = new ObjectWriterContext(savedContext, settings, rootNameScope, runtime); } else { if (schemaContext == null) { throw this.WithLineInfo(new XamlInternalException()); } this._context = new ObjectWriterContext(schemaContext, settings, rootNameScope, runtime); this._context.AddNamespacePrefix("xml", "http://www.w3.org/XML/1998/namespace"); } this._context.IsInitializedCallback = this; this._deferringWriter = new DeferringWriter(this._context); this._rootNamescope = null; }
private static IControl PopupContentControlTemplate(PopupContentControl control, INameScope scope) { return(new Popup { Name = "popup", PlacementTarget = control, Child = new ContentPresenter { [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty], } }.RegisterInNameScope(scope)); }
public RootServiceProvider(INameScope nameScope) { _nameScope = nameScope; }
/// <summary> /// Initializes a new instance of the <see cref="TemplateAppliedEventArgs"/> class. /// </summary> /// <param name="nameScope">The applied template's name scope.</param> public TemplateAppliedEventArgs(INameScope nameScope) : base(TemplatedControl.TemplateAppliedEvent) { NameScope = nameScope; }
public static void SetNameScope(BindableObject bindable, INameScope value) { bindable.SetValue(NameScopeProperty, value); }
public NameScope(INameScope parent) { _parent = parent; }
internal static T FindByName <T>(this INameScope namescope, string name) => (T)namescope.FindByName(name);
private static object GetScopeElement(DependencyObject target, string elementName) { INameScope nameScope = NameScope.GetContainingNameScope(target); return(nameScope != null?nameScope.FindName(elementName) : ObservableValue.UnsetValue); }
public static InitializeContext SetNameScope(this InitializeContext context, INameScope nameScope) { return(new InitializeContext(context.Target, context.ParentContext, nameScope, context.TemplatedParent, context.ValueSource)); }
public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty, INameScope scope) { if (objectAndParents == null) { throw new ArgumentNullException(nameof(objectAndParents)); } if (objectAndParents.Length == 0) { throw new ArgumentException(); } this.objectAndParents = objectAndParents; this.targetProperty = targetProperty; this.scope = scope; }
private void HandleBeforeProperties(object createdObject, ref DependencyObject rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope) { if (createdObject is FrameworkElement || createdObject is FrameworkContentElement) { // We want to set TemplateChild on the parent if we are dealing with the root // We MUST wait until the object is wired into the Template vis TemplateNameScope.RegisterName if (rootObject == null) { rootObject = WireRootObjectToParent(createdObject, rootObject, container, feContainer, nameScope); } InvalidatePropertiesOnTemplate(container, createdObject); } }
/// <summary> /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class. /// </summary> /// <param name="root">The root visual.</param> /// <param name="nameScope">The name scope.</param> public VisualTreeAttachmentEventArgs(IRenderRoot root, INameScope nameScope) { Root = root; NameScope = nameScope; }
private void RegisterName(ObjectWriterContext ctx, string name, object inst, XamlType xamlType, INameScope nameScope, INameScope parentNameScope, bool isRoot) { INameScope objA = nameScope; NameScopeDictionary dictionary = nameScope as NameScopeDictionary; if (dictionary != null) { objA = dictionary.UnderlyingNameScope; } if (object.ReferenceEquals(objA, inst) && !isRoot) { nameScope = parentNameScope; } if (!(inst is NameFixupToken)) { try { nameScope.RegisterName(name, inst); } catch (Exception exception) { if (CriticalExceptions.IsCriticalException(exception)) { throw; } throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("NameScopeException", new object[] { exception.Message }), exception)); } } }
/// <inheritdoc/> protected override void OnTemplateApplied(INameScope nameScope) { Presenter = nameScope.Find <IItemsPresenter>("PART_ItemsPresenter"); }
public NameScopeDictionary(INameScope underlyingNameScope) { _names = new FrugalObjectList <string>(); _underlyingNameScope = underlyingNameScope ?? throw new ArgumentNullException(nameof(underlyingNameScope)); }
/// <summary> /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class. /// </summary> /// <param name="root">The root visual.</param> /// <param name="nameScope">The name scope.</param> public VisualTreeAttachmentEventArgs(IRenderRoot root, INameScope nameScope) { Root = root; NameScope = nameScope; }
public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg) { XamlIlTypes = cfg.WellKnownTypes; AvaloniaObject = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject"); IAvaloniaObject = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject"); AvaloniaObjectExtensions = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions"); AvaloniaProperty = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty"); AvaloniaPropertyT = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1"); BindingPriority = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority"); IBinding = cfg.TypeSystem.GetType("Avalonia.Data.IBinding"); IDisposable = cfg.TypeSystem.GetType("System.IDisposable"); Transitions = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions"); AssignBindingAttribute = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute"); AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject, AvaloniaProperty, IBinding, cfg.WellKnownTypes.Object); UnsetValueType = cfg.TypeSystem.GetType("Avalonia.UnsetValueType"); StyledElement = cfg.TypeSystem.GetType("Avalonia.StyledElement"); INameScope = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope"); INameScopeRegister = INameScope.GetMethod( new FindMethodMethodSignature("Register", XamlIlTypes.Void, XamlIlTypes.String, XamlIlTypes.Object) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); INameScopeComplete = INameScope.GetMethod( new FindMethodMethodSignature("Complete", XamlIlTypes.Void) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); NameScope = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope"); NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope", XamlIlTypes.Void, StyledElement, INameScope) { IsStatic = true }); AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", XamlIlTypes.Void, false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority); IPropertyInfo = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo"); ClrPropertyInfo = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo"); PropertyPath = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath"); PropertyPathBuilder = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder"); IPropertyAccessor = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor"); PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory"); CompiledBindingPathBuilder = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder"); CompiledBindingPath = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath"); CompiledBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension"); ResolveByNameExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension"); DataTemplate = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate"); IDataTemplate = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate"); IItemsPresenterHost = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost"); ItemsRepeater = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater"); ReflectionBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension"); RelativeSource = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource"); Long = cfg.TypeSystem.GetType("System.Int64"); Uri = cfg.TypeSystem.GetType("System.Uri"); FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily"); FontFamilyConstructorUriName = FontFamily.GetConstructor(new List <IXamlType> { Uri, XamlIlTypes.String }); (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount) { var type = cfg.TypeSystem.GetType(name); var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList()); return(type, ctor); } (Thickness, ThicknessFullConstructor) = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4); (Point, PointFullConstructor) = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2); (Vector, VectorFullConstructor) = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2); (Size, SizeFullConstructor) = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2); (Matrix, MatrixFullConstructor) = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6); (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4); }
/// <summary> /// Finds the target element of a Storyboard.TargetName property. /// </summary> /// <remarks> /// This is using a different set of FindName rules than that used /// by ResolveBeginStoryboardName for finding a BeginStoryboard object due /// to the different FindName behavior in templated objects. /// /// The templated object name is the name attached to the /// FrameworkElementFactory that created the object. There are many of them /// created, one per templated object. So we need to use Template.FindName() /// to find the templated child using the context of the templated parent. /// /// Note that this FindName() function on the template class is /// completely different from the INameScope.FindName() function on the /// same class /// </remarks> internal static DependencyObject ResolveTargetName( string targetName, INameScope nameScope, DependencyObject element ) { object nameScopeUsed = null; object namedObject = null; DependencyObject targetObject = null; FrameworkElement fe = element as FrameworkElement; FrameworkContentElement fce = element as FrameworkContentElement; if( fe != null ) { if( nameScope != null ) { namedObject = ((FrameworkTemplate)nameScope).FindName(targetName, fe); nameScopeUsed = nameScope; } else { namedObject = fe.FindName(targetName); nameScopeUsed = fe; } } else if( fce != null ) { Debug.Assert( nameScope == null ); namedObject = fce.FindName(targetName); nameScopeUsed = fce; } else { throw new InvalidOperationException( SR.Get(SRID.Storyboard_NoNameScope, targetName)); } if( namedObject == null ) { throw new InvalidOperationException( SR.Get(SRID.Storyboard_NameNotFound, targetName, nameScopeUsed.GetType().ToString())); } targetObject = namedObject as DependencyObject; if( targetObject == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_TargetNameNotDependencyObject, targetName )); } return targetObject; }
async void FindAsync(INameScope scope, string name) { _found = await scope.FindAsync(name); }
public static T RegisterInNameScope <T>(this T control, INameScope scope) where T : StyledElement { scope.Register(control.Name, control); return(control); }
public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) { string instance; string str; IPropertyId shadowProperty; ReferenceStep referenceStep = propertyKey as ReferenceStep; ViewNode item = viewNode.Properties[propertyKey]; if (item != null && DocumentNodeUtilities.IsBinding(item.DocumentNode) && referenceStep != null) { ReferenceStep referenceStep1 = referenceStep; if (context.UseShadowProperties) { shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, viewNode.DocumentNode.Type); } else { shadowProperty = null; } IPropertyId propertyId = shadowProperty; if (propertyId != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, propertyId)) { referenceStep1 = propertyId as ReferenceStep; } if (referenceStep1 != null) { IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode; if (instantiatedElementViewNode == null) { referenceStep1.ClearValue(viewNode.Instance); } else { foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements) { referenceStep1.ClearValue(instantiatedElement); } } } } if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey) && InstanceBuilderOperations.GetIsInlinedResourceWithoutNamescope(viewNode)) { InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode); return; } INameScope nameScope = context.NameScope; bool flag = (nameScope == null ? false : propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey)); if (flag) { ViewNode item1 = viewNode.Properties[propertyKey]; if (item1 != null) { str = item1.Instance as string; } else { str = null; } string str1 = str; if (!string.IsNullOrEmpty(str1) && nameScope.FindName(str1) != null) { context.NameScope.UnregisterName(str1); } } if ((!context.IsSerializationScope || !(propertyKey is Event)) && (context.IsSerializationScope || !DesignTimeProperties.IsDocumentOnlyDesignTimeProperty(propertyKey))) { base.UpdateProperty(context, viewNode, propertyKey, valueNode); } else { InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode); } if (flag) { ViewNode viewNode1 = viewNode.Properties[propertyKey]; if (viewNode1 != null) { instance = viewNode1.Instance as string; } else { instance = null; } string str2 = instance; if (!string.IsNullOrEmpty(str2)) { try { if (!str2.StartsWith("~", StringComparison.Ordinal) && !str2.Contains(".")) { if (nameScope.FindName(str2) != null) { nameScope.UnregisterName(str2); } nameScope.RegisterName(str2, viewNode.Instance); } } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; ViewNodeManager viewNodeManager = viewNode1.ViewNodeManager; CultureInfo currentCulture = CultureInfo.CurrentCulture; string instanceBuilderUnableToRegisterName = ExceptionStringTable.InstanceBuilderUnableToRegisterName; object[] objArray = new object[] { str2 }; viewNodeManager.OnException(viewNode1, new InstanceBuilderException(string.Format(currentCulture, instanceBuilderUnableToRegisterName, objArray), argumentException, viewNode1.DocumentNode, viewNode), false); } } } }
/// <inheritdoc/> public InstancedBinding Initiate( IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null, bool enableDataValidation = false) { Contract.Requires <ArgumentNullException>(target != null); anchor = anchor ?? DefaultAnchor?.Target; enableDataValidation = enableDataValidation && Priority == BindingPriority.LocalValue; ExpressionObserver observer; INameScope nameScope = null; NameScope?.TryGetTarget(out nameScope); var(node, mode) = ExpressionObserverBuilder.Parse(Path, enableDataValidation, TypeResolver, nameScope); if (ElementName != null) { observer = CreateElementObserver( (target as IStyledElement) ?? (anchor as IStyledElement), ElementName, node); } else if (Source != null) { observer = CreateSourceObserver(Source, node); } else if (RelativeSource == null) { if (mode == SourceMode.Data) { observer = CreateDataContextObserver( target, node, targetProperty == StyledElement.DataContextProperty, anchor); } else { observer = new ExpressionObserver( (target as IStyledElement) ?? (anchor as IStyledElement), node); } } else if (RelativeSource.Mode == RelativeSourceMode.DataContext) { observer = CreateDataContextObserver( target, node, targetProperty == StyledElement.DataContextProperty, anchor); } else if (RelativeSource.Mode == RelativeSourceMode.Self) { observer = CreateSourceObserver( (target as IStyledElement) ?? (anchor as IStyledElement), node); } else if (RelativeSource.Mode == RelativeSourceMode.TemplatedParent) { observer = CreateTemplatedParentObserver( (target as IStyledElement) ?? (anchor as IStyledElement), node); } else if (RelativeSource.Mode == RelativeSourceMode.FindAncestor) { if (RelativeSource.Tree == TreeType.Visual && RelativeSource.AncestorType == null) { throw new InvalidOperationException("AncestorType must be set for RelativeSourceMode.FindAncestor when searching the visual tree."); } observer = CreateFindAncestorObserver( (target as IStyledElement) ?? (anchor as IStyledElement), RelativeSource, node); } else { throw new NotSupportedException(); } var fallback = FallbackValue; // If we're binding to DataContext and our fallback is UnsetValue then override // the fallback value to null, as broken bindings to DataContext must reset the // DataContext in order to not propagate incorrect DataContexts to child controls. // See Avalonia.Markup.UnitTests.Data.DataContext_Binding_Should_Produce_Correct_Results. if (targetProperty == StyledElement.DataContextProperty && fallback == AvaloniaProperty.UnsetValue) { fallback = null; } var converter = Converter; var targetType = targetProperty?.PropertyType ?? typeof(object); // We only respect `StringFormat` if the type of the property we're assigning to will // accept a string. Note that this is slightly different to WPF in that WPF only applies // `StringFormat` for target type `string` (not `object`). if (!string.IsNullOrWhiteSpace(StringFormat) && (targetType == typeof(string) || targetType == typeof(object))) { converter = new StringFormatValueConverter(StringFormat, converter); } var subject = new BindingExpression( observer, targetType, fallback, TargetNullValue, converter ?? DefaultValueConverter.Instance, ConverterParameter, Priority); return(new InstancedBinding(subject, Mode, Priority)); }
/// <summary> /// Begins all animations underneath this storyboard, clock tree starts at the given containing object. /// </summary> internal void BeginCommon( DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, bool isControllable, Int64 layer) { if (containingObject == null) { throw new ArgumentNullException("containingObject"); } if (!HandoffBehaviorEnum.IsDefined(handoffBehavior)) { throw new ArgumentException(SR.Get(SRID.Storyboard_UnrecognizedHandoffBehavior)); } if (BeginTime == null) { // a null BeginTime means to not allocate or start the clock return; } // It's not possible to begin when there is no TimeManager. This condition // is known to occur during app shutdown. Since an app being shut down // won't care about its Storyboards, we silently exit. // If we don't exit here, we'll need to catch and handle the "no time // manager" exception implemented for bug #1247862 if( MediaContext.CurrentMediaContext.TimeManager == null ) { return; } if( TraceAnimation.IsEnabled ) { TraceAnimation.TraceActivityItem( TraceAnimation.StoryboardBegin, this, Name, containingObject, nameScope ); } // This table maps an [object,property] key pair to one or more clocks. // If we have knowledge of whether this Storyboard was changed between multiple // Begin(), we can cache this. But we don't know, so we don't cache. HybridDictionary simplePathClockMappings = new HybridDictionary(); // Create (and Begin) a clock tree corresponding to this Storyboard timeline tree Clock storyboardClockTree = CreateClock(isControllable); // We now have one or more clocks that are created from this storyboard. // However, the individual clocks are not necessarily intended for // the containing object so we need to do a tree walk and sort out // which clocks go on which objects and their properties. ClockTreeWalkRecursive( storyboardClockTree, containingObject, nameScope, null, /* target object */ null, /* target object name */ null, /* target property path */ handoffBehavior, simplePathClockMappings, layer); // Apply the storyboard's animation clocks we found in the tree walk ApplyAnimationClocks( simplePathClockMappings, handoffBehavior, layer ); if (isControllable) { // Save a reference to this clock tree on the containingObject. We // need it there in order to control this clock tree later. SetStoryboardClock(containingObject, storyboardClockTree); } return; }
private void Begin(FrameworkElement target, INameScope nameScope, object layerOwner) { if (Storyboard != null) { Storyboard.Begin(target, nameScope, HandoffBehavior, layerOwner); } }
/// <summary> /// Finds a BeginStoryboard with the given name, following the rules /// governing Storyboard. Returns null if not found. /// </summary> /// <remarks> /// If a name scope is given, look there and nowhere else. In the /// absense of name scope, use Framework(Content)Element.FindName which /// has its own complex set of rules for looking up name scopes. /// /// This is a different set of rules than from that used to look up /// the TargetName. BeginStoryboard name is registered with the template /// INameScope on a per-template basis. So we look it up using /// INameScope.FindName(). This is a function completely different from /// Template.FindName(). /// </remarks> internal static BeginStoryboard ResolveBeginStoryboardName( string targetName, INameScope nameScope, FrameworkElement fe, FrameworkContentElement fce) { object namedObject = null; BeginStoryboard beginStoryboard = null; if( nameScope != null ) { namedObject = nameScope.FindName(targetName); if( namedObject == null ) { throw new InvalidOperationException( SR.Get(SRID.Storyboard_NameNotFound, targetName, nameScope.GetType().ToString())); } } else if( fe != null ) { namedObject = fe.FindName(targetName); if( namedObject == null ) { throw new InvalidOperationException( SR.Get(SRID.Storyboard_NameNotFound, targetName, fe.GetType().ToString())); } } else if( fce != null ) { namedObject = fce.FindName(targetName); if( namedObject == null ) { throw new InvalidOperationException( SR.Get(SRID.Storyboard_NameNotFound, targetName, fce.GetType().ToString())); } } else { throw new InvalidOperationException( SR.Get(SRID.Storyboard_NoNameScope, targetName)); } beginStoryboard = namedObject as BeginStoryboard; if( beginStoryboard == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_BeginStoryboardNameNotFound, targetName)); } return beginStoryboard; }
/// <inheritdoc/> protected override void OnTemplateApplied(INameScope nameScope) { base.OnTemplateApplied(nameScope); if (Parent.TemplatedParent != null) { if (_presenterSubscription != null) { _presenterSubscription.Dispose(); _presenterSubscription = null; } var presenter = Presenter; if (presenter != null) { presenter.GetObservable(ContentPresenter.ChildProperty) .Subscribe(SetTemplatedParentAndApplyChildTemplates); } } }
/// <summary> /// When we've found a media clock, try to find a corresponding media /// element and attach the media clock to that element. /// </summary> private static void ApplyMediaClock( INameScope nameScope, DependencyObject containingObject, DependencyObject currentObject, string currentObjectName, MediaClock mediaClock ) { MediaElement targetMediaElement = null; if( currentObjectName != null ) { // Find the object named as the current target name. DependencyObject mentor = Helper.FindMentor(containingObject); targetMediaElement = ResolveTargetName(currentObjectName, nameScope, mentor ) as MediaElement; if( targetMediaElement == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_MediaElementNotFound, currentObjectName )); } } else if( currentObject != null ) { targetMediaElement = currentObject as MediaElement; } else { targetMediaElement = containingObject as MediaElement; } if( targetMediaElement == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_MediaElementRequired)); } targetMediaElement.Clock = mediaClock; }
public NameScope (INameScope external) { this.external = external; }
/// <summary> /// Provides the attached property set accessor for the NameScope attached property. /// </summary> /// <param name="dependencyObject">Object to change XAML namescope for.</param> /// <param name="value">The new XAML namescope, using an interface cast.</param> public static void SetNameScope(DependencyObject dependencyObject, INameScope value) { dependencyObject.SetValue(NameScopeProperty, value); }
public ExpressionParser(bool enableValidation, Func <string, string, Type> typeResolver, INameScope nameScope) { _typeResolver = typeResolver; _nameScope = nameScope; _enableValidation = enableValidation; }
protected override void OnTemplateApplied(INameScope nameScope) { if (_popup != null) { _popup.Opened -= PopupOpened; } _popup = nameScope.Get<Popup>("PART_Popup"); _popup.Opened += PopupOpened; }
public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg) { XamlIlTypes = cfg.WellKnownTypes; AvaloniaObject = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject"); IAvaloniaObject = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject"); AvaloniaObjectExtensions = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions"); AvaloniaProperty = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty"); AvaloniaPropertyT = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1"); StyledPropertyT = cfg.TypeSystem.GetType("Avalonia.StyledProperty`1"); AvaloniaAttachedPropertyT = cfg.TypeSystem.GetType("Avalonia.AttachedProperty`1"); BindingPriority = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority"); AvaloniaObjectSetStyledPropertyValue = AvaloniaObject .FindMethod(m => m.IsPublic && !m.IsStatic && m.Name == "SetValue" && m.Parameters.Count == 3 && m.Parameters[0].Name == "StyledPropertyBase`1" && m.Parameters[2].Equals(BindingPriority)); IBinding = cfg.TypeSystem.GetType("Avalonia.Data.IBinding"); IDisposable = cfg.TypeSystem.GetType("System.IDisposable"); ICommand = cfg.TypeSystem.GetType("System.Windows.Input.ICommand"); Transitions = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions"); AssignBindingAttribute = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute"); DependsOnAttribute = cfg.TypeSystem.GetType("Avalonia.Metadata.DependsOnAttribute"); DataTypeAttribute = cfg.TypeSystem.GetType("Avalonia.Metadata.DataTypeAttribute"); AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject, AvaloniaProperty, IBinding, cfg.WellKnownTypes.Object); UnsetValueType = cfg.TypeSystem.GetType("Avalonia.UnsetValueType"); StyledElement = cfg.TypeSystem.GetType("Avalonia.StyledElement"); IStyledElement = cfg.TypeSystem.GetType("Avalonia.IStyledElement"); INameScope = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope"); INameScopeRegister = INameScope.GetMethod( new FindMethodMethodSignature("Register", XamlIlTypes.Void, XamlIlTypes.String, XamlIlTypes.Object) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); INameScopeComplete = INameScope.GetMethod( new FindMethodMethodSignature("Complete", XamlIlTypes.Void) { IsStatic = false, DeclaringOnly = true, IsExactMatch = true }); NameScope = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope"); NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope", XamlIlTypes.Void, StyledElement, INameScope) { IsStatic = true }); AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", IDisposable, false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority); IPropertyInfo = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo"); ClrPropertyInfo = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo"); PropertyPath = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath"); PropertyPathBuilder = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder"); IPropertyAccessor = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor"); PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory"); CompiledBindingPathBuilder = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder"); CompiledBindingPath = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath"); CompiledBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension"); ResolveByNameExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension"); DataTemplate = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate"); IDataTemplate = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate"); IItemsPresenterHost = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost"); ItemsRepeater = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater"); ReflectionBindingExtension = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension"); RelativeSource = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource"); UInt = cfg.TypeSystem.GetType("System.UInt32"); Int = cfg.TypeSystem.GetType("System.Int32"); Long = cfg.TypeSystem.GetType("System.Int64"); Uri = cfg.TypeSystem.GetType("System.Uri"); FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily"); FontFamilyConstructorUriName = FontFamily.GetConstructor(new List <IXamlType> { Uri, XamlIlTypes.String }); (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount) { var type = cfg.TypeSystem.GetType(name); var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList()); return(type, ctor); } (Thickness, ThicknessFullConstructor) = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4); (Point, PointFullConstructor) = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2); (Vector, VectorFullConstructor) = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2); (Size, SizeFullConstructor) = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2); (Matrix, MatrixFullConstructor) = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6); (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4); RelativeUnit = cfg.TypeSystem.GetType("Avalonia.RelativeUnit"); RelativePoint = cfg.TypeSystem.GetType("Avalonia.RelativePoint"); RelativePointFullConstructor = RelativePoint.GetConstructor(new List <IXamlType> { XamlIlTypes.Double, XamlIlTypes.Double, RelativeUnit }); GridLength = cfg.TypeSystem.GetType("Avalonia.Controls.GridLength"); GridLengthConstructorValueType = GridLength.GetConstructor(new List <IXamlType> { XamlIlTypes.Double, cfg.TypeSystem.GetType("Avalonia.Controls.GridUnitType") }); Color = cfg.TypeSystem.GetType("Avalonia.Media.Color"); StandardCursorType = cfg.TypeSystem.GetType("Avalonia.Input.StandardCursorType"); Cursor = cfg.TypeSystem.GetType("Avalonia.Input.Cursor"); CursorTypeConstructor = Cursor.GetConstructor(new List <IXamlType> { StandardCursorType }); ColumnDefinition = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinition"); ColumnDefinitions = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinitions"); RowDefinition = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinition"); RowDefinitions = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinitions"); Classes = cfg.TypeSystem.GetType("Avalonia.Controls.Classes"); StyledElementClassesProperty = StyledElement.Properties.First(x => x.Name == "Classes" && x.PropertyType.Equals(Classes)); ClassesBindMethod = cfg.TypeSystem.GetType("Avalonia.StyledElementExtensions") .FindMethod("BindClass", IDisposable, false, IStyledElement, cfg.WellKnownTypes.String, IBinding, cfg.WellKnownTypes.Object); IBrush = cfg.TypeSystem.GetType("Avalonia.Media.IBrush"); ImmutableSolidColorBrush = cfg.TypeSystem.GetType("Avalonia.Media.Immutable.ImmutableSolidColorBrush"); ImmutableSolidColorBrushConstructorColor = ImmutableSolidColorBrush.GetConstructor(new List <IXamlType> { UInt }); TypeUtilities = cfg.TypeSystem.GetType("Avalonia.Utilities.TypeUtilities"); TextDecorationCollection = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorationCollection"); TextDecorations = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorations"); TextTrimming = cfg.TypeSystem.GetType("Avalonia.Media.TextTrimming"); ISetter = cfg.TypeSystem.GetType("Avalonia.Styling.ISetter"); IResourceDictionary = cfg.TypeSystem.GetType("Avalonia.Controls.IResourceDictionary"); ResourceDictionary = cfg.TypeSystem.GetType("Avalonia.Controls.ResourceDictionary"); ResourceDictionaryDeferredAdd = ResourceDictionary.FindMethod("AddDeferred", XamlIlTypes.Void, true, XamlIlTypes.Object, cfg.TypeSystem.GetType("System.Func`2").MakeGenericType( cfg.TypeSystem.GetType("System.IServiceProvider"), XamlIlTypes.Object)); }
/// <summary> /// Returns the nearest element implementing <see cref="INameScope"/>, stepping up the /// logical tree from our context object. /// </summary> /// <param name="result">Returns the nearest name scope element, if there is one.</param> /// <returns><c>true</c>, if a name scope could be found, <c>false</c> if it could not /// be found (yet).</returns> protected bool FindNameScope(out INameScope result) { result = null; DependencyObject current = _contextObject; if (current == null) { #if DEBUG_BINDINGS DebugOutput("FindNameScope doesn't have a current context"); #endif return false; } while (current != null) { if (current is INameScope) { result = current as INameScope; return true; } if (current is UIElement) { UIElement uiElement = (UIElement) current; AbstractProperty templateNameScopeProperty = uiElement.TemplateNameScopeProperty; AttachToSourcePathProperty(templateNameScopeProperty); if ((result = ((INameScope) templateNameScopeProperty.GetValue())) != null) return true; } if (!FindParent(current, out current, FindParentMode.HybridPreferLogicalTree)) return false; } return false; }
public CompiledBindingPathBuilder ElementName(INameScope nameScope, string name) { _elements.Add(new ElementNameElement(nameScope, name)); return(this); }
/// <summary> /// Sets the value of the attached <see cref="NameScopeProperty"/> on a visual. /// </summary> /// <param name="visual">The visual.</param> /// <param name="value">The value to set.</param> public static void SetNameScope(Visual visual, INameScope value) { visual.SetValue(NameScopeProperty, value); }
public ElementNameElement(INameScope nameScope, string name) { NameScope = nameScope; Name = name; }
private static DependencyObject WireRootObjectToParent(object createdObject, DependencyObject rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope) { rootObject = createdObject as DependencyObject; if (rootObject != null) { // Add the root to the appropriate tree. if (feContainer != null) { // Put the root object into FE.Templatechild (must be a UIElement). UIElement rootElement = rootObject as UIElement; if (rootElement == null) { throw new InvalidOperationException(SR.Get(SRID.TemplateMustBeFE, new object[] { rootObject.GetType().FullName })); } feContainer.TemplateChild = rootElement; Debug.Assert(!(rootElement is FrameworkElement) || ((FrameworkElement)rootElement).TemplateChildIndex != -1); } // If we have a container that is not a FE, add to the logical tree of the FEF else if (container != null) { FrameworkElement feResult; FrameworkContentElement fceResult; Helper.DowncastToFEorFCE(rootObject, out feResult, out fceResult, true); FrameworkElementFactory.AddNodeToLogicalTree((FrameworkContentElement)container, rootObject.GetType(), feResult != null, feResult, fceResult); } // Set the TemplateNameScope on the root if (NameScope.GetNameScope(rootObject) == null) { NameScope.SetNameScope(rootObject, nameScope); } } return rootObject; }
public ObjectWriterContext(XamlSavedContext savedContext, XamlObjectWriterSettings settings, INameScope rootNameScope, XamlRuntime runtime) : base(savedContext.SchemaContext) { INameScopeDictionary dictionary; this._stack = new XamlContextStack <ObjectWriterFrame>(savedContext.Stack, false); if (settings != null) { this._settings = settings.StripDelegates(); } this._runtime = runtime; this.BaseUri = savedContext.BaseUri; switch (savedContext.SaveContextType) { case SavedContextType.Template: dictionary = null; if (rootNameScope != null) { dictionary = rootNameScope as INameScopeDictionary; if (dictionary == null) { dictionary = new NameScopeDictionary(rootNameScope); } break; } dictionary = new NameScope(); break; case SavedContextType.ReparseValue: case SavedContextType.ReparseMarkupExtension: this._savedDepth = this._stack.Depth - 1; return; default: return; } this._stack.PushScope(); this._savedDepth = this._stack.Depth; this._stack.CurrentFrame.NameScopeDictionary = dictionary; this._stack.PushScope(); }
/// <summary> /// Sets the TemplatedParent property for a control created from the control template and /// applies the templates of nested templated controls. Also adds each control to its name /// scope if it has a name. /// </summary> /// <param name="control">The control.</param> /// <param name="nameScope">The name scope.</param> private void SetupTemplateControls(IControl control, INameScope nameScope) { // If control.TemplatedParent is null at this point, then the control is our templated // child so set its TemplatedParent and register it with its name scope. if (control.TemplatedParent == null) { control.SetValue(TemplatedParentProperty, this); if (control.Name != null) { nameScope.Register(control.Name, control); } } control.ApplyTemplate(); if (!(control is IPresenter && control.TemplatedParent == this)) { foreach (IControl child in control.GetVisualChildren()) { SetupTemplateControls(child, nameScope); } } }
public ObjectWriterContext(XamlSchemaContext schemaContext, XamlObjectWriterSettings settings, INameScope rootNameScope, XamlRuntime runtime) : base(schemaContext) { this._stack = new XamlContextStack <ObjectWriterFrame>(() => new ObjectWriterFrame()); INameScopeDictionary dictionary = null; if (rootNameScope == null) { dictionary = new NameScope(); } else { dictionary = rootNameScope as INameScopeDictionary; if (dictionary == null) { dictionary = new NameScopeDictionary(rootNameScope); } } this._stack.CurrentFrame.NameScopeDictionary = dictionary; this._stack.PushScope(); if (settings != null) { this._settings = settings.StripDelegates(); } this._runtime = runtime; this._savedDepth = 0; }
public override void WriteEndObject() { this.ThrowIfDisposed(); this._deferringWriter.WriteEndObject(); if (this._deferringWriter.Handled) { if (this._deferringWriter.Mode == DeferringMode.TemplateReady) { XamlNodeList list = this._deferringWriter.CollectTemplateList(); this._context.PushScope(); this._context.CurrentInstance = list.GetReader(); } } else { if (this._nextNodeMustBeEndMember) { string message = System.Xaml.SR.Get("ValueMustBeFollowedByEndMember"); throw this.WithLineInfo(new XamlObjectWriterException(message)); } if (this._context.CurrentType == null) { string str2 = System.Xaml.SR.Get("NoTypeInCurrentFrame_EO"); throw this.WithLineInfo(new XamlObjectWriterException(str2)); } if (this._context.CurrentProperty != null) { string str3 = System.Xaml.SR.Get("OpenPropertyInCurrentFrame_EO", new object[] { this._context.CurrentType.ToString(), this._context.CurrentProperty.ToString() }); throw this.WithLineInfo(new XamlObjectWriterException(str3)); } bool flag = this.HasUnresolvedChildren(this._context.CurrentInstance); bool flag2 = this._context.CurrentInstance is NameFixupToken; if (!this._context.CurrentIsObjectFromMember) { if (this._context.CurrentInstance == null) { this.Logic_CreateAndAssignToParentStart(this._context); } XamlType currentType = this._context.CurrentType; object currentInstance = this._context.CurrentInstance; this.OnAfterProperties(currentInstance); if (this._context.CurrentType.IsMarkupExtension) { if (flag) { this.Logic_DeferProvideValue(this._context); } else { this.ExecutePendingAdds(this._context.CurrentType, this._context.CurrentInstance); this.Logic_EndInit(this._context); currentInstance = this._context.CurrentInstance; this.Logic_AssignProvidedValue(this._context); if (this._context.CurrentInstanceRegisteredName != null) { if (this._nameFixupGraph != null) { this.TriggerNameResolution(currentInstance, this._context.CurrentInstanceRegisteredName); } this._context.CurrentInstanceRegisteredName = null; } currentInstance = this._context.CurrentInstance; flag2 = currentInstance is NameFixupToken; flag = !flag2 && this.HasUnresolvedChildren(currentInstance); } } else { if ((this._context.LiveDepth > 1) && !this._context.CurrentWasAssignedAtCreation) { this.Logic_DoAssignmentToParentProperty(this._context); } if (flag) { if (this._context.LiveDepth > 1) { this.AddDependencyForUnresolvedChildren(this._context.CurrentInstance, this._context.ParentProperty, this._context.ParentInstance, this._context.ParentType, this._context.ParentIsObjectFromMember, null); } } else if (!flag2) { this.ExecutePendingAdds(this._context.CurrentType, this._context.CurrentInstance); this.Logic_EndInit(this._context); } } } else { if (flag) { this.AddDependencyForUnresolvedChildren(this._context.CurrentInstance, this._context.ParentProperty, this._context.ParentInstance, this._context.ParentType, this._context.ParentIsObjectFromMember, null); } else { this.ExecutePendingAdds(this._context.CurrentType, this._context.CurrentInstance); } if (this._context.ParentIsPropertyValueSet) { throw this.WithLineInfo(new XamlDuplicateMemberException(this._context.ParentProperty, this._context.ParentType)); } } this._lastInstance = this._context.CurrentInstance; string currentInstanceRegisteredName = this._context.CurrentInstanceRegisteredName; if (this._context.LiveDepth == 1) { this._rootNamescope = this._context.RootNameScope; } this._context.PopScope(); if (flag) { this._nameFixupGraph.IsOffTheStack(this._lastInstance, currentInstanceRegisteredName, this._lineNumber, this._linePosition); } else if (flag2) { if (currentInstanceRegisteredName != null) { NameFixupToken token = (NameFixupToken) this._lastInstance; if ((token.FixupType == FixupType.ObjectInitializationValue) && !token.CanAssignDirectly) { token.SavedContext.Stack.PreviousFrame.InstanceRegisteredName = currentInstanceRegisteredName; } } } else if (this._nameFixupGraph != null) { this.TriggerNameResolution(this._lastInstance, currentInstanceRegisteredName); } if ((this._context.LiveDepth == 0) && !this._inDispose) { this.CompleteNameReferences(); this._context.RaiseNameScopeInitializationCompleteEvent(); } } }
internal static T FindByName <T>(this INameScope namescope, string name) { return((T)namescope.FindByName(name)); }
public void Clear() { this.ThrowIfDisposed(); while (this._context.LiveDepth > 0) { this._context.PopScope(); } this._rootNamescope = null; this._nextNodeMustBeEndMember = false; this._deferringWriter.Clear(); this._context.PushScope(); }
/// <summary> /// Initializes a new instance of the <see cref="StyledElement"/> class. /// </summary> public StyledElement() { _nameScope = this as INameScope; _isAttachedToLogicalTree = this is IStyleRoot; }
/// <summary> /// Registers each control with its name scope. /// </summary> /// <param name="control">The control.</param> /// <param name="nameScope">The name scope.</param> private void RegisterNames(IControl control, INameScope nameScope) { if (control.Name != null) { nameScope.Register(control.Name, control); } if (control.TemplatedParent == this) { foreach (IControl child in control.GetVisualChildren()) { RegisterNames(child, nameScope); } } }
/// <summary> /// Initializes a new instance of the <see cref="Control"/> class. /// </summary> public Control() { _nameScope = this as INameScope; _isAttachedToLogicalTree = this is IStyleRoot; }