Caliburn.Micro.View.ExecuteOnLoad C# (CSharp) Метод

ExecuteOnLoad() публичный статический Метод

Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
public static ExecuteOnLoad ( global::Xamarin.Forms.VisualElement element, RoutedEventHandler handler ) : bool
element global::Xamarin.Forms.VisualElement The element.
handler RoutedEventHandler The handler.
Результат bool
        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

        }

Usage Example

Пример #1
0
        static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Execute.InDesignMode || e.NewValue == null || e.NewValue == e.OldValue)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            View.ExecuteOnLoad(fe, delegate
            {
                var target       = e.NewValue;
                var containerKey = e.NewValue as string;

                if (containerKey != null)
                {
                    target = IoC.GetInstance(null, containerKey);
                }

                d.SetValue(View.IsScopeRootProperty, true);

                var context = string.IsNullOrEmpty(fe.Name)
                                  ? fe.GetHashCode().ToString()
                                  : fe.Name;

                ViewModelBinder.Bind(target, d, context);
            });
        }
All Usage Examples Of Caliburn.Micro.View::ExecuteOnLoad