/// <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 }
/// <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 }
/// <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 }
public static void ExecuteOnLayoutUpdated(FrameworkElement element, EventHandler handler) { EventHandler onLayoutUpdate = null; #endif onLayoutUpdate = (s, e) => { element.LayoutUpdated -= onLayoutUpdate; handler(element, e); }; element.LayoutUpdated += onLayoutUpdate; }
/// <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 }
void IAttachedObject.Attach(DependencyObject dependencyObject) { #else void IAttachedObject.Attach(FrameworkElement dependencyObject) { #endif associatedObject = dependencyObject; } void IAttachedObject.Detach() { associatedObject = null; }
/// <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); } }
/// <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; } }
/// <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 }
/// <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;
/// <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) {
/// <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 }
/// <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;
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 }
/// <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) {