예제 #1
0
        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
        public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler handler)
        {
#if XFORMS
            handler(element, new RoutedEventArgs());
            return(true);
#else
#if SILVERLIGHT
            if ((bool)element.GetValue(IsLoadedProperty))
            {
#elif WinRT
            if (IsElementLoaded(element))
            {
#else
            if (element.IsLoaded)
            {
#endif
                handler(element, new RoutedEventArgs());
                return(true);
            }

            RoutedEventHandler loaded = null;
            loaded = (s, e) => {
                element.Loaded -= loaded;
#if SILVERLIGHT
                element.SetValue(IsLoadedProperty, true);
#endif
                handler(s, e);
            };
            element.Loaded += loaded;
            return(false);
#endif
        }
예제 #2
0
        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
        public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler handler)
        {
#if XFORMS
            handler(element, new RoutedEventArgs());
            return(true);
#else
#if WINDOWS_UWP
            if (IsElementLoaded(element))
            {
#else
            if (element.IsLoaded)
            {
#endif
                handler(element, new RoutedEventArgs());
                return(true);
            }

            RoutedEventHandler loaded = null;
            loaded = (s, e) => {
                element.Loaded -= loaded;
                handler(s, e);
            };
            element.Loaded += loaded;
            return(false);
#endif
        }
예제 #3
0
        /// <summary>
        /// Creates a binding on a <see cref="Parameter"/>.
        /// </summary>
        /// <param name="target">The target to which the message is applied.</param>
        /// <param name="parameter">The parameter object.</param>
        /// <param name="elementName">The name of the element to bind to.</param>
        /// <param name="path">The path of the element to bind to.</param>
        /// <param name="bindingMode">The binding mode to use.</param>
        public static void BindParameter(FrameworkElement target, Parameter parameter, string elementName, string path, BindingMode bindingMode)
        {
#if XFORMS
            var element = elementName == "$this" ? target : null;

            if (element == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                path = ConventionManager.GetElementConvention(element.GetType()).ParameterProperty;
            }

            var binding = new Binding(path)
            {
                Source = element,
                Mode   = bindingMode
            };

            parameter.SetBinding(Parameter.ValueProperty, binding);
#else
            var element = elementName == "$this"
                ? target
                : BindingScope.GetNamedElements(target).FindName(elementName);
            if (element == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                path = ConventionManager.GetElementConvention(element.GetType()).ParameterProperty;
            }
#if WINDOWS_UWP
            var binding = new Binding
            {
                Path   = new PropertyPath(path),
                Source = element,
                Mode   = bindingMode
            };
#else
            var binding = new Binding(path)
            {
                Source = element,
                Mode   = bindingMode
            };
#endif

#if !WINDOWS_UWP
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
#endif

            BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding);
#endif
        }
예제 #4
0
        public static void ExecuteOnLayoutUpdated(FrameworkElement element, EventHandler handler)
        {
            EventHandler onLayoutUpdate = null;
#endif
            onLayoutUpdate = (s, e) => {
                element.LayoutUpdated -= onLayoutUpdate;
                handler(element, e);
            };
            element.LayoutUpdated += onLayoutUpdate;
        }
예제 #5
0
        /// <summary>
        /// Executes the handler when the element is unloaded.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        public static void ExecuteOnUnload(FrameworkElement element, RoutedEventHandler handler)
        {
#if !XFORMS
            RoutedEventHandler unloaded = null;
            unloaded = (s, e) => {
                element.Unloaded -= unloaded;
                handler(s, e);
            };
            element.Unloaded += unloaded;
#endif
        }
예제 #6
0
        void IAttachedObject.Attach(DependencyObject dependencyObject) {
#else
        void IAttachedObject.Attach(FrameworkElement dependencyObject)
        {
#endif
            associatedObject = dependencyObject;
        }

        void IAttachedObject.Detach()
        {
            associatedObject = null;
        }
예제 #7
0
        void IAttachedObject.Attach(DependencyObject dependencyObject)
        {
#else
        void IAttachedObject.Attach(FrameworkElement dependencyObject)
        {
#endif
            associatedObject = dependencyObject;
        }

        void IAttachedObject.Detach()
        {
            associatedObject = null;
        }
예제 #8
0
        /// <summary>
        /// Determines whether the specified <paramref name="element"/> is loaded.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>true if the element is loaded; otherwise, false.
        /// </returns>
        public static bool IsElementLoaded(FrameworkElement element)
        {
            try
            {
                if ((element.Parent ?? VisualTreeHelper.GetParent(element)) != null)
                {
                    return(true);
                }

                var rootVisual = Window.Current.Content;

                if (rootVisual != null)
                {
                    return(element == rootVisual);
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
예제 #9
0
        /// <summary>
        /// Determines whether the specified <paramref name="element"/> is loaded.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>true if the element is loaded; otherwise, false.
        /// </returns>
        public static bool IsElementLoaded(FrameworkElement element) {
            try
            {
                if ((element.Parent ?? VisualTreeHelper.GetParent(element)) != null)
                {
                    return true;
                }

                var rootVisual = Window.Current.Content;

                if (rootVisual != null)
                {
                    return element == rootVisual;
                }

                return false;

            }
            catch
            {
                return false;
            }
        }
예제 #10
0
        /// <summary>
        /// Executes the handler when the element is unloaded.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        public static void ExecuteOnUnload(FrameworkElement element, RoutedEventHandler handler) {
#if !XFORMS
            RoutedEventHandler unloaded = null;
            unloaded = (s, e) => {
                element.Unloaded -= unloaded;
                handler(s, e);
            };
            element.Unloaded += unloaded;
#endif
        }
예제 #11
0
        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
        public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler handler) {
#if XFORMS
            handler(element, new RoutedEventArgs());
            return true;
#else
#if SILVERLIGHT
            if ((bool)element.GetValue(IsLoadedProperty)) {
#elif WinRT
            if (IsElementLoaded(element)) {
#else
            if(element.IsLoaded) {
#endif
                handler(element, new RoutedEventArgs());
                return true;
            }

            RoutedEventHandler loaded = null;
            loaded = (s, e) => {
                element.Loaded -= loaded;
#if SILVERLIGHT
                element.SetValue(IsLoadedProperty, true);
#endif
                handler(s, e);
            };
            element.Loaded += loaded;
            return false;
#endif

        }
예제 #12
0
        /// <summary>
        /// Executes the handler the next time the elements's LayoutUpdated event fires.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
#if WinRT
        public static void ExecuteOnLayoutUpdated(FrameworkElement element, EventHandler <object> handler)
        {
            EventHandler <object> onLayoutUpdate = null;
예제 #13
0
        /// <summary>
        /// Executes the handler when the element is unloaded.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
#if NOESIS
        public static void ExecuteOnUnload(FrameworkElement element, FrameworkElement.UnloadedHandler handler)
        {
예제 #14
0
        /// <summary>
        /// Creates a binding on a <see cref="Parameter"/>.
        /// </summary>
        /// <param name="target">The target to which the message is applied.</param>
        /// <param name="parameter">The parameter object.</param>
        /// <param name="elementName">The name of the element to bind to.</param>
        /// <param name="path">The path of the element to bind to.</param>
        /// <param name="bindingMode">The binding mode to use.</param>
        public static void BindParameter(FrameworkElement target, Parameter parameter, string elementName, string path, BindingMode bindingMode)
        {
#if XFORMS
            var element = elementName == "$this" ? target : null;

            if (element == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                path = ConventionManager.GetElementConvention(element.GetType()).ParameterProperty;
            }

            var binding = new Binding(path)
            {
                Source = element,
                Mode   = bindingMode
            };

            parameter.SetBinding(Parameter.ValueProperty, binding);
#else
            var element = elementName == "$this"
                ? target
                : BindingScope.GetNamedElements(target).FindName(elementName);
            if (element == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                path = ConventionManager.GetElementConvention(element.GetType()).ParameterProperty;
            }
#if WinRT
            var binding = new Binding
            {
                Path   = new PropertyPath(path),
                Source = element,
                Mode   = bindingMode
            };
#else
            var binding = new Binding(path)
            {
                Source = element,
                Mode   = bindingMode
            };
#endif

#if (SILVERLIGHT && !SL5)
            var expression = (BindingExpression)BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding);

            var field = element.GetType().GetField(path + "Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
            if (field == null)
            {
                return;
            }

            ConventionManager.ApplySilverlightTriggers(element, (DependencyProperty)field.GetValue(null), x => expression, null, null);
#else
#if !WinRT
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
#endif

            BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding);
#endif
#endif
        }
예제 #15
0
        /// <summary>
        /// Executes the handler the next time the elements's LayoutUpdated event fires.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
#if WinRT
        public static void ExecuteOnLayoutUpdated(FrameworkElement element, EventHandler<object> handler) {
            EventHandler<object> onLayoutUpdate = null;
예제 #16
0
        public static void ExecuteOnLayoutUpdated(FrameworkElement element, EventHandler handler) {
            EventHandler onLayoutUpdate = null;
#endif
#if !XFORMS
            onLayoutUpdate = (s, e) => {
                element.LayoutUpdated -= onLayoutUpdate;
                handler(element, e);
            };
            element.LayoutUpdated += onLayoutUpdate;
#endif
        }
예제 #17
0
        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
#if NOESIS
        public static bool ExecuteOnLoad(FrameworkElement element, FrameworkElement.LoadedHandler handler)
        {