madskristensen / Community.VisualStudio.Toolkit

A community toolkit for writing Visual Studio extensions
Other
24 stars 3 forks source link

VsTheme Improvements #18

Closed reduckted closed 3 years ago

reduckted commented 3 years ago

I've cleaned up the UseVsTheme attached property, and also improved it in a few ways:

madskristensen commented 3 years ago

This is amazing work. Thank you so much!!!

madskristensen commented 3 years ago

When I open RunnerWindowControl.xaml and MultiInstanceWindowControl.xaml I get this error message in the design which is failing to load.

image

The designer loads correctly again after setting UseVsTheme to false like so:

toolkit:Themes.UseVsTheme="True"

ThemeWindowControl.xaml shows another error that may be related:

image

reduckted commented 3 years ago

I was able to get the full stack trace of the error:

System.ArgumentNullException: Value cannot be null.
Parameter name: item
   at System.Windows.ResourceDictionaryCollection.InsertItem(Int32 index, ResourceDictionary item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Microsoft.VisualStudio.PlatformUI.ThemedDialogStyleLoader.MergeDefaultThemedDialogStyles(FrameworkElement element)
   at Microsoft.VisualStudio.PlatformUI.ThemedDialogStyleLoader.OnUseDefaultThemedDialogStylesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Microsoft.VisualStudio.PlatformUI.ThemedDialogStyleLoader.SetUseDefaultThemedDialogStyles(FrameworkElement element, Boolean value)
   at Community.VisualStudio.Toolkit.Themes.UseVsThemePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

At a guess, I'd say that when the UseDefaultThemedDialogStyles dependency property is set, the resource with the key VsResourceKeys.ThemedDialogDefaultStylesKey couldn't be found, but the MergeDefaultThemedDialogStyles doesn't check if it was found and just adds the null ResourceDictionary to the collection, causing the exception.

27 should fix it.

As for not being able to load ThemeWindowDemo, that seems to be caused by the use of WatermarkedTextBox on that control. When I removed that control, the ThemeWindowDemo control was able to be created in the designer.