Exemple #1
0
        /// <summary>
        /// Sets the templated parent, with the ability to control the propagation of the templated parent.
        /// </summary>
        /// <param name="templatedParent">The parent to apply.</param>
        /// <param name="applyToChildren">
        /// Applies the templated parent to children if true. False is generally used when a control is template-able
        /// to avoid propagating its own templated parent to its children.
        /// </param>
        public void SetTemplatedParent(FrameworkElement templatedParent)
        {
            try
            {
                if (_isApplyingTemplateBindings || _bindingsSuspended)
                {
                    // If we reach this point, this means that a propagation loop has been detected, and
                    // we can skip the current binder.
                    // This can happen if a DependencyObject-typed DependencyProperty contains a reference
                    // to one of its ancestors.
                    return;
                }

                _isApplyingTemplateBindings = true;

                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().DebugFormat(
                        "{0}.ApplyTemplateBindings({1}/{2}) (h:{3:X8})",
                        _originalObjectType.ToString(),
                        templatedParent?.GetType().ToString() ?? "[null]",
                        templatedParent?.GetHashCode().ToString("X8", CultureInfo.InvariantCulture) ?? "[null]",
                        ActualInstance?.GetHashCode()
                        );
                }

                _properties.ApplyTemplatedParent(templatedParent);

                ApplyChildrenBindable(templatedParent, isTemplatedParent: true);
            }
            finally
            {
                _isApplyingTemplateBindings = false;
            }
        }
        private void GetExtraPropertyInfo(FrameworkElement frameworkElement, out object extraPropertyValue, out TypeInfo extraPropertyType)
        {
            extraPropertyValue = null;
            extraPropertyType = null;

            if (ExtraArgumentPropertyName != null)
            {
                var extraPropertyInfo = frameworkElement.GetType().GetRuntimeProperty(ExtraArgumentPropertyName);
                if (extraPropertyInfo == null)
                    Debug.WriteLine(string.Format("Cannot find property {0} on UI element {1} when handling event {2}", ExtraArgumentPropertyName, frameworkElement.GetType().FullName, EventName));
                else
                {
                    extraPropertyValue = extraPropertyInfo.GetValue(frameworkElement);
                    if (extraPropertyValue != null)
                        extraPropertyType = extraPropertyValue.GetType().GetTypeInfo();
                }
            }
        }
 protected override void ApplyBindings(FrameworkElement attachedObject,
                                       IEnumerable<MvxBindingDescription> bindingDescriptions)
 {
     var actualType = attachedObject.GetType();
     foreach (var bindingDescription in bindingDescriptions)
     {
         ApplyBinding(bindingDescription, actualType, attachedObject);
     }
 }
Exemple #4
0
        public static void Appear(FrameworkElement el, int millisecondPostpone = 0)
        {
            if (el.GetType().Name == "SplashScreenView")
            {
                el.Opacity =1.0;
                return;
            }


            DispatchedHandler invokedHandler = new DispatchedHandler(() =>
            {
                TranslateTransform translateTransform = new TranslateTransform();
                el.RenderTransform = translateTransform;
                translateTransform.X = (double)Animation.pixelsMove;
                if (translateTransform != null)
                {
                    SplineDoubleKeyFrame splineDoubleKeyFrame = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame.KeyTime = TimeSpan.FromMilliseconds((double)(10 + millisecondPostpone));
                    splineDoubleKeyFrame.Value = (double)Animation.pixelsMove;
                    SplineDoubleKeyFrame splineDoubleKeyFrame2 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame2.KeyTime = TimeSpan.FromMilliseconds((double)(350 + millisecondPostpone));
                    splineDoubleKeyFrame2.Value = 0.0;
                    splineDoubleKeyFrame2.KeySpline = new KeySpline();
                    splineDoubleKeyFrame2.KeySpline.ControlPoint1 = new Point(0.0, 0.0);
                    splineDoubleKeyFrame2.KeySpline.ControlPoint2 = new Point(0.0, 1.0);
                    DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(doubleAnimationUsingKeyFrames, translateTransform);
                    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, "(TranslateTransform.X)");
                    doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame);
                    doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame2);
                    SplineDoubleKeyFrame splineDoubleKeyFrame3 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame3.KeyTime = TimeSpan.FromMilliseconds((double)millisecondPostpone);
                    splineDoubleKeyFrame3.Value = 0.0;
                    SplineDoubleKeyFrame splineDoubleKeyFrame4 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame4.KeyTime = TimeSpan.FromMilliseconds((double)(300 + millisecondPostpone));
                    splineDoubleKeyFrame4.Value = 1.0;
                    DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames2 = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(doubleAnimationUsingKeyFrames2, el);
                    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames2, "(UIElement.Opacity)");
                    doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame3);
                    doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame4);
                    Storyboard storyboard = new Storyboard();
                    storyboard.Children.Add(doubleAnimationUsingKeyFrames);
                    storyboard.Children.Add(doubleAnimationUsingKeyFrames2);
                    storyboard.Begin();
                }

            });


            el.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler).GetResults();
        }
        public void SetTemplatedParent(FrameworkElement?templatedParent)
        {
#if !HAS_EXPENSIVE_TRYFINALLY
            // The try/finally incurs a very large performance hit in mono-wasm, and SetValue is in a very hot execution path.
            // See https://github.com/mono/mono/issues/13653 for more details.
            try
#endif
            {
                if (_isApplyingTemplateBindings || _bindingsSuspended)
                {
                    // If we reach this point, this means that a propagation loop has been detected, and
                    // we can skip the current binder.
                    // This can happen if a DependencyObject-typed DependencyProperty contains a reference
                    // to one of its ancestors.
                    return;
                }

                _isApplyingTemplateBindings = true;

                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().DebugFormat(
                        "{0}.ApplyTemplateBindings({1}/{2}) (h:{3:X8})",
                        _originalObjectType.ToString(),
                        templatedParent?.GetType().ToString() ?? "[null]",
                        templatedParent?.GetHashCode().ToString("X8", CultureInfo.InvariantCulture) ?? "[null]",
                        ActualInstance?.GetHashCode()
                        );
                }

                _properties.ApplyTemplatedParent(templatedParent);

                ApplyChildrenBindable(templatedParent, isTemplatedParent: true);
            }
#if !HAS_EXPENSIVE_TRYFINALLY
            finally
#endif
            {
                _isApplyingTemplateBindings = false;
            }
        }
 /// <summary>
 /// Attaches to the specified object.
 /// 
 /// </summary>
 /// <param name="dependencyObject">The object to attach to.</param><exception cref="T:System.InvalidOperationException">The Behavior is already hosted on a different element.</exception><exception cref="T:System.InvalidOperationException">dependencyObject does not satisfy the Behavior type constraint.</exception>
 public override void Attach(FrameworkElement dependencyObject)
 {
     if (dependencyObject == this.AssociatedObject)
     {
         return;
     }
     if (this.AssociatedObject != null)
     {
         throw new InvalidOperationException("Cannot host behavior multiple times.");
     }
     if (dependencyObject != null && !this.AssociatedObjectTypeConstraint.GetTypeInfo().IsAssignableFrom(dependencyObject.GetType().GetTypeInfo()))
     {
         throw new InvalidOperationException("Type constraint violated.");
     }
     else
     {
         this.AssociatedObject = dependencyObject;
         this.OnAssociatedObjectChanged();
         //we need to fix the datacontext for databinding to work
         this.ConfigureDataContext();
         this.OnAttached();
     }
 }
 /// <summary>
 /// Attaches to the specified object.
 /// 
 /// </summary>
 /// <param name="frameworkElement">The object to attach to.</param><exception cref="T:System.InvalidOperationException">The Behavior is already hosted on a different element.</exception><exception cref="T:System.InvalidOperationException">dependencyObject does not satisfy the Behavior type constraint.</exception>
 public override void Attach(FrameworkElement frameworkElement)
 {
     if (frameworkElement == this.AssociatedObject)
     {
         return;
     }
     if (this.AssociatedObject != null)
     {
         throw new InvalidOperationException("Cannot host behavior multiple times.");
     }
     if (frameworkElement != null && !this.AssociatedObjectTypeConstraint.GetTypeInfo().IsAssignableFrom(frameworkElement.GetType().GetTypeInfo()))
     {
         throw new InvalidOperationException("Type constraint violated.");
     }
     else
     {
         this.AssociatedObject = frameworkElement;
         this.OnAssociatedObjectChanged();
         //Attach handles the DataContext
         base.Attach(frameworkElement);                
         this.OnAttached();
     }
 }
 /// <summary>
 /// Attaches to the specified object.
 /// 
 /// </summary>
 /// <param name="frameworkElement">The object to attach to.</param><exception cref="T:System.InvalidOperationException">Cannot host the same trigger on more than one object at a time.</exception><exception cref="T:System.InvalidOperationException">dependencyObject does not satisfy the trigger type constraint.</exception>
 public override async void Attach(FrameworkElement frameworkElement)
 {
     if (frameworkElement == this.AssociatedObject)
     {
         return;
     }
     if (this.AssociatedObject != null)
     {
         throw new InvalidOperationException("Cannot Host Trigger Multiple Times");
     }
     if (frameworkElement != null && !this.AssociatedObjectTypeConstraint.GetTypeInfo().IsAssignableFrom(frameworkElement.GetType().GetTypeInfo()))
     {
         throw new InvalidOperationException("Type Constraint Violated");
     }
     else
     {
         this.AssociatedObject = frameworkElement;                
         this.OnAssociatedObjectChanged();
         //we need to fix the datacontext for databinding to work
         await this.ConfigureDataContext();
         this.Actions.Attach(frameworkElement);
         this.OnAttached();
     }
 }
            public ContentDialogWrapper(FrameworkElement window)
            {
                _window = window;
                if (_closingEvent == null)
                    _closingEvent = window.GetType().GetRuntimeEvent("Closing");

                Delegate handler = ServiceProvider
                    .ReflectionManager
                    .TryCreateDelegate(_closingEvent.EventHandlerType, this, OnClosingMethod);
                if (handler == null)
                {
                    Tracer.Error("The provider cannot create delegate for event '{0}'", _closingEvent.EventHandlerType);
                    return;
                }
                _token = (EventRegistrationToken)_closingEvent.AddMethod.InvokeEx(window, handler);
            }
        /// <summary>
        /// Applies the Binding represented by the SetterValueBindingHelper.
        /// </summary>
        /// <param name="element">Element to apply the Binding to.</param>
        /// <param name="item">SetterValueBindingHelper representing the Binding.</param>
        private static void ApplyBinding(FrameworkElement element, SetterValueBindingHelper item)
        {
            if ((null == item.Property) || (null == item.Binding))
            {
                throw new ArgumentException(
                    "SetterValueBindingHelper's Property and Binding must both be set to non-null values.");
            }

            // Get the type on which to set the Binding
            Type type = null;
            TypeInfo typeInfo = null;
            if (null == item.Type)
            {
                // No type specified; setting for the specified element
                type = element.GetType();
                typeInfo = type.GetTypeInfo();
            }
            else
            {
                // Try to get the type from the type system
                type = System.Type.GetType(item.Type);
                if (null == type)
                {
                    // Search for the type in the list of assemblies
                    foreach (var assembly in AssembliesToSearch)
                    {
                        // Match on short or full name
                        typeInfo = assembly.DefinedTypes
                            .Where(t => (t.FullName == item.Type) || (t.Name == item.Type))
                            .FirstOrDefault();
                        if (null != typeInfo)
                        {
                            // Found; done searching
                            break;
                        }
                    }
                    if (null == typeInfo)
                    {
                        // Unable to find the requested type anywhere
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Unable to access type \"{0}\". Try using an assembly qualified type name.",
                                                                  item.Type));
                    }
                }
                else
                {
                    typeInfo = type.GetTypeInfo();
                }
            }

            // Get the DependencyProperty for which to set the Binding
            DependencyProperty property = null;
            var field = typeInfo.GetDeclaredProperty(item.Property + "Property"); // type.GetRuntimeField(item.Property + "Property");
            if (null != field)
            {
                property = field.GetValue(null) as DependencyProperty;
            }
            if (null == property)
            {
                // Unable to find the requsted property
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          "Unable to access DependencyProperty \"{0}\" on type \"{1}\".",
                                                          item.Property, type.Name));
            }

            // Set the specified Binding on the specified property
            element.SetBinding(property, item.Binding);
        }
        // </snippet3303>
        // </snippet300>

        private static object GetViewModelForView(FrameworkElement view)
        {
            // Mapping of view models base on view type (or instance) goes here
            if (factories.ContainsKey(view.GetType().ToString()))
                return factories[view.GetType().ToString()]();
            return null;
        }
        /// <summary>
        /// This method will change the visibility of the framework element that is passed as an argument, to collapsed.
        /// It will then use the siblingType parameter to find the other element that should be toggled to visible
        /// </summary>
        /// <param name="caller">FrameworkElement that should be collapsed</param>
        /// <param name="siblingType">The type of the sibling that should be visible</param>
        // This was originally ment for an inferiour solution, with no usercontrol.
        // However, i like the solution i made, so im going to keep this.
        private void ToggleVisibility(FrameworkElement caller, Type siblingType)
        {
            var sibling = caller?
                                .FindName(
                                          caller
                                          .Name?
                                          .Replace(
                                                   caller
                                                   .GetType()
                                                   .Name
                                                   .ToLower(),

                                                   siblingType
                                                   .Name
                                                   .ToLower()
                                                   )
                                          ) as FrameworkElement;

            if (sibling == null) return; // TODO implement some kind of error handeling/notification.

            caller.Visibility = Visibility.Collapsed;
            sibling.Visibility = Visibility.Visible;
        }