public void SwitchProviders(ILaunchSettingsUIProvider oldProvider)
        {
            // Get the old custom control and disconnect from notifications
            if (oldProvider?.CustomUI?.DataContext is INotifyPropertyChanged context)
            {
                context.PropertyChanged -= OnCustomUIStateChanged;

                if (context is INotifyDataErrorInfo notifyDataErrorInfo)
                {
                    notifyDataErrorInfo.ErrorsChanged -= OnCustomUIErrorsChanged;
                }
            }

            // Now hook into the current providers notifications. We do that after having set the profile on the provider
            // so that we don't get notifications while the control is initializing. Note that this is likely the first time the
            // custom control is asked for and we want to call it and have it created prior to setting the active profile
            UserControl customControl = ActiveProvider?.CustomUI;

            if (customControl != null)
            {
                ActiveProvider.ProfileSelected(CurrentLaunchSettings);

                context = customControl.DataContext as INotifyPropertyChanged;
                if (context != null)
                {
                    context.PropertyChanged += OnCustomUIStateChanged;
                }

                if (context is INotifyDataErrorInfo notifyDataErrorInfo)
                {
                    notifyDataErrorInfo.ErrorsChanged += OnCustomUIErrorsChanged;
                }
            }
        }
Esempio n. 2
0
        private bool ActiveProviderSupportsProperty(string propertyName)
        {
            ILaunchSettingsUIProvider activeProvider = ActiveProvider;

            return(activeProvider?.ShouldEnableProperty(propertyName) ?? false);
        }