Example #1
0
        /// <summary>
        /// Called when the <c>DataContext</c> property of the <c>TargetView</c> has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
#pragma warning disable AvoidAsyncVoid // Avoid async void
        public override async void OnTargetViewDataContextChanged(object sender, Catel.MVVM.Views.DataContextChangedEventArgs e)
#pragma warning restore AvoidAsyncVoid // Avoid async void
        {
            if (IsCurrentDataContext(e))
            {
                return;
            }

            if (!IsTargetViewLoaded && !IsLoading)
            {
                return;
            }

            // Fix in WinRT to make sure inner grid is created
            CreateViewModelWrapper();

            // Fix for CTL-307: DataContextChanged is invoked before Unloaded because Parent is set to null
            var targetControlParent = TargetView.GetParent();

            if (targetControlParent is null)
            {
                return;
            }

            base.OnTargetViewDataContextChanged(sender, e);

            var dataContext = GetDataContext(TargetView);

            if (dataContext.IsSentinelBindingObject())
            {
                return;
            }

            if (!IsUnloading)
            {
                // Note: don't respect view model lifetime management here, the IViewModelFactory should return null if
                // no vm should be created and users *really* want to disable this kind of core Catel behavior
                await UpdateDataContextToUseViewModelAsync(dataContext);
            }
        }
Example #2
0
        /// <summary>
        /// Called when the <c>DataContext</c> property of the <c>TargetView</c> has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
#pragma warning disable AvoidAsyncVoid // Avoid async void
        public override async void OnTargetViewDataContextChanged(object sender, Catel.MVVM.Views.DataContextChangedEventArgs e)
#pragma warning restore AvoidAsyncVoid // Avoid async void
        {
            if (IsCurrentDataContext(e))
            {
                return;
            }

            if (!IsTargetViewLoaded && !IsLoading)
            {
                return;
            }

            // Fix in WinRT to make sure inner grid is created
            CreateViewModelWrapper();

            // Fix for CTL-307: DataContextChanged is invoked before Unloaded because Parent is set to null
            var targetControlParent = TargetView.GetParent();

            if (targetControlParent == null)
            {
                return;
            }

            base.OnTargetViewDataContextChanged(sender, e);

            var dataContext = TargetView.DataContext;

            if (dataContext.IsSentinelBindingObject())
            {
                return;
            }

            if (!IsUnloading)
            {
                await UpdateDataContextToUseViewModelAsync(dataContext);
            }
        }
Example #3
0
        /// <summary>
        /// Called when the <c>DataContext</c> property of the <c>TargetView</c> has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        public override void OnTargetViewDataContextChanged(object sender, Catel.MVVM.Views.DataContextChangedEventArgs e)
        {
            if (e.AreEqual)
            {
                return;
            }

            if (!IsTargetViewLoaded && !IsLoading)
            {
                return;
            }

            // Fix in WinRT to make sure inner grid is created
            CreateViewModelWrapper();

            // Fix for CTL-307: DataContextChanged is invoked before Unloaded because Parent is set to null
            var targetControlParent = TargetView.GetParent();

            if (targetControlParent == null)
            {
                return;
            }

            base.OnTargetViewDataContextChanged(sender, e);

            var dataContext = TargetView.DataContext;

            if (dataContext.IsSentinelBindingObject())
            {
                return;
            }

            if (!IsUnloading)
            {
                UpdateDataContextToUseViewModel(dataContext);
            }
        }