Exemplo n.º 1
0
        /// <summary>
        /// Called when the <see cref="TargetView"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetViewLoadedAsync"/> which can be overriden for custom
        /// behavior. This method is required to protect from duplicate loaded events.
        /// </remarks>
#pragma warning disable AvoidAsyncVoid // Avoid async void
        private async void OnTargetViewLoadedInternal(object sender, EventArgs e)
#pragma warning restore AvoidAsyncVoid // Avoid async void
        {
            if (!CanLoad)
            {
                return;
            }

            Log.Debug($"Target view '{TargetViewType?.Name}' has been loaded");

            var view = TargetView;

            if (view != null)
            {
                _viewManager.RegisterView(view);
            }

            IsTargetViewLoaded = true;

            var dataContext = view.DataContext;

            LastKnownDataContext = (dataContext != null) ? new WeakReference(dataContext) : null;

            await OnTargetViewLoadedAsync(sender, e);

            TargetView.EnsureVisualTree();

            var targetViewAsViewModelContainer = TargetView as IViewModelContainer;

            if (targetViewAsViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.InitializeViewToViewModelMappings(targetViewAsViewModelContainer);
            }

            TargetView.Dispatch(() =>
            {
#pragma warning disable 4014
                // No need to await
                InitializeViewModelAsync();
#pragma warning restore 4014
            });

            IsLoading = false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the <see cref="TargetView"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetViewLoaded"/> which can be overriden for custom
        /// behavior. This method is required to protect from duplicate loaded events.
        /// </remarks>
        private void OnTargetViewLoadedInternal(object sender, EventArgs e)
        {
            if (!CanLoad)
            {
                return;
            }

            Log.Debug("Target view '{0}' is loaded", TargetView.GetType().Name);

            var view = TargetView;

            if (view != null)
            {
                _viewManager.RegisterView(view);
            }

            IsTargetViewLoaded = true;

            OnTargetViewLoaded(sender, e);

            TargetView.EnsureVisualTree();

            var targetViewAsViewModelContainer = TargetView as IViewModelContainer;

            if (targetViewAsViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.InitializeViewToViewModelMappings(targetViewAsViewModelContainer);
            }

            TargetView.Dispatch(() =>
            {
#pragma warning disable 4014
                // No need to await
                InitializeViewModelAsync();
#pragma warning restore 4014
            });

            IsLoading = false;
        }