From 2dfefcda1d30b7a60f25da48cc087941e767de9e Mon Sep 17 00:00:00 2001 From: jkuehner Date: Fri, 13 Feb 2015 09:43:37 +0100 Subject: [PATCH 1/7] Buggfix Nullable Enum as Property --- .../WpfDesign/WpfDesign/Project/Metadata.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs index ca4509c64f..6f9b16df77 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs @@ -82,9 +82,16 @@ namespace ICSharpCode.WpfDesign /// public static IEnumerable GetStandardValues(Type type) { + var baseT = Nullable.GetUnderlyingType(type); + if (type.IsEnum) { return Enum.GetValues(type); } + + if (baseT != null && baseT.IsEnum) { + return Enum.GetValues(baseT); + } + List values; lock (standardValues) { if (standardValues.TryGetValue(type, out values)) { From af55ad837c92210cf00856cfaa533cf228e01cea Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Thu, 26 Feb 2015 12:53:39 +0100 Subject: [PATCH 2/7] Better Nullable Enum support --- .../Project/Controls/NullableComboBox.cs | 68 +++++ .../Project/Controls/NullableComboBox.xaml | 249 ++++++++++++++++++ .../PropertyGrid/Editors/ComboBoxEditor.xaml | 32 +-- .../Project/WpfDesign.Designer.csproj | 9 + .../Project/themes/generic.xaml | 1 + .../Project/PropertyGrid/EditorManager.cs | 3 + 6 files changed, 347 insertions(+), 15 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.xaml diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.cs new file mode 100644 index 0000000000..38cc01a094 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.cs @@ -0,0 +1,68 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace ICSharpCode.WpfDesign.Designer.Controls +{ + /// + /// A ComboBox wich is Nullable + /// + public class NullableComboBox : ComboBox + { + static NullableComboBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(NullableComboBox), new FrameworkPropertyMetadata(typeof(NullableComboBox))); + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + var btn = GetTemplateChild("PART_ClearButton") as Button; + + btn.Click += btn_Click; + } + + void btn_Click(object sender, RoutedEventArgs e) + { + var clearButton = (Button)sender; + var parent = VisualTreeHelper.GetParent(clearButton); + + while (!(parent is ComboBox)) + { + parent = VisualTreeHelper.GetParent(parent); + } + + var comboBox = (ComboBox)parent; + comboBox.SelectedIndex = -1; + } + + public bool IsNullable + { + get { return (bool)GetValue(IsNullableProperty); } + set { SetValue(IsNullableProperty, value); } + } + + public static readonly DependencyProperty IsNullableProperty = + DependencyProperty.Register("IsNullable", typeof(bool), typeof(NullableComboBox), new PropertyMetadata(true)); + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.xaml new file mode 100644 index 0000000000..9a76b2cda2 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NullableComboBox.xaml @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + M 0 0 L 3.5 4 L 7 0 Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/ComboBoxEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/ComboBoxEditor.xaml index fdbf774116..a511967afb 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/ComboBoxEditor.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/ComboBoxEditor.xaml @@ -1,15 +1,17 @@ - - - - - - - + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index a9daa804f8..f6b7c00f54 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -56,6 +56,9 @@ False 3.0 + + 3.0 + 3.0 @@ -84,6 +87,7 @@ Configuration\GlobalAssemblyInfo.cs + @@ -130,6 +134,7 @@ WrapItemContextMenu.xaml + @@ -316,6 +321,7 @@ + Designer @@ -513,4 +519,7 @@ + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/generic.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/generic.xaml index 99acb3ace4..fe250843ea 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/generic.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/generic.xaml @@ -5,6 +5,7 @@ > + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs index 9569b09d95..ca079c8746 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs @@ -64,6 +64,9 @@ namespace ICSharpCode.WpfDesign.PropertyGrid if (standardValues != null) { var itemsControl = (ItemsControl)Activator.CreateInstance(defaultComboboxEditor); itemsControl.ItemsSource = standardValues; + if (Nullable.GetUnderlyingType(property.ReturnType) != null) { + itemsControl.GetType().GetProperty("IsNullable").SetValue(itemsControl, true, null); //In this Class we don't know the Nullable Combo Box + } return itemsControl; } return (FrameworkElement)Activator.CreateInstance(defaultTextboxEditor); From feb875847a28fe13bbe881ba880b7463f0a0ed5f Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Thu, 26 Feb 2015 12:54:07 +0100 Subject: [PATCH 3/7] Fix a Null ref Exception --- .../WpfDesign.Designer/Project/OutlineView/OutlineNode.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs index 261d1b47e5..d015be4503 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs @@ -67,8 +67,8 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView public static IOutlineNode Create(DesignItem designItem) { - IOutlineNode node; - if (!outlineNodes.TryGetValue(designItem, out node)) { + IOutlineNode node = null; + if (designItem != null && !outlineNodes.TryGetValue(designItem, out node)) { node = new OutlineNode(designItem); outlineNodes[designItem] = node; } From b511e54d0843f34ac8abd0b2276c5ad1d267d1a7 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Thu, 26 Feb 2015 12:54:26 +0100 Subject: [PATCH 4/7] XML Comment fixes --- samples/XamlDesigner/ExtensionMethods.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/samples/XamlDesigner/ExtensionMethods.cs b/samples/XamlDesigner/ExtensionMethods.cs index ff09256e1d..3c582b0adc 100644 --- a/samples/XamlDesigner/ExtensionMethods.cs +++ b/samples/XamlDesigner/ExtensionMethods.cs @@ -1,3 +1,21 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + using System; using System.Collections.Generic; using System.Linq; From 1c95b77ab3ef3e65bfa2eb247ad338f1de3ad230 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Thu, 26 Feb 2015 12:57:47 +0100 Subject: [PATCH 5/7] Add a designItembinding, this can be used when you create your own Property Editors, they should not only Bind to the Value of the View, no they should also change the Properties of the underlaying DesignItem --- .../MarkupExtensions/DesignItemBinding.cs | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs new file mode 100644 index 0000000000..b0340d7379 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs @@ -0,0 +1,151 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; +using System.Windows.Markup; +using ICSharpCode.WpfDesign.UIExtensions; + +[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "ICSharpCode.WpfDesign.Designer.MarkupExtensions")] + + +namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions +{ + /// + /// A Binding to a DesignItem of Object + /// + /// This can be used for Example your own Property Pages for Designer Objects + /// + public class DesignItemBinding : MarkupExtension + { + private string _propertyName; + private Binding _binding; + private DesignItemSetConverter _converter; + private DependencyProperty _targetProperty; + private FrameworkElement _targetObject; + + public bool SingleItemProperty { get; set; } + + public UpdateSourceTrigger UpdateSourceTrigger { get; set; } + + public DesignItemBinding(string path) + { + this._propertyName = path; + + UpdateSourceTrigger = UpdateSourceTrigger.Default; + } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + IProvideValueTarget service = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget)); + _targetObject = service.TargetObject as FrameworkElement; + _targetProperty = service.TargetProperty as DependencyProperty; + + _targetObject.DataContextChanged += targetObject_DataContextChanged; + + return null; + } + + void targetObject_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) + { + var ctx = ((FrameworkElement) sender).DataContext as FrameworkElement; + + var surface = ctx.TryFindParent(); + + if (surface != null) + { + _binding = new Binding(_propertyName); + _binding.Source = ctx; + _binding.UpdateSourceTrigger = UpdateSourceTrigger; + _binding.Mode = BindingMode.TwoWay; + + var designItem = surface.DesignContext.Services.Component.GetDesignItem(ctx); + + _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty); + _binding.Converter = _converter; + + _targetObject.SetBinding(_targetProperty, _binding); + } + else + { + _targetObject.ClearValue(_targetProperty); + } + } + + private class DesignItemSetConverter : IValueConverter + { + private DesignItem _designItem; + private string _property; + private bool _singleItemProperty; + + public DesignItemSetConverter(DesignItem desigItem, string property, bool singleItemProperty) + { + this._designItem = desigItem; + this._property = property; + this._singleItemProperty = singleItemProperty; + } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + var changeGroup = _designItem.OpenGroup("Property: " + _property); + + try + { + var property = _designItem.Properties.GetProperty(_property); + + property.SetValue(value); + + + if (!_singleItemProperty && _designItem.Services.Selection.SelectedItems.Count > 1) + { + var msg = MessageBox.Show("Apply changes to all selected Items","", MessageBoxButton.YesNo); + if (msg == MessageBoxResult.Yes) + { + foreach (var item in _designItem.Services.Selection.SelectedItems) + { + try + { + property = item.Properties.GetProperty(_property); + } + catch(Exception) + { } + if (property != null) + property.SetValue(value); + } + } + } + + changeGroup.Commit(); + } + catch (Exception) + { + changeGroup.Abort(); + } + + return value; + } + } + } +} From dd84bfb5427bff2a8aacbea61f8ed59e914eaf92 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Thu, 26 Feb 2015 13:52:42 +0100 Subject: [PATCH 6/7] Fix a few XML Comments --- .../WpfDesign.XamlDom/Project/DesignInstanceExtension.cs | 3 +++ .../WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignInstanceExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignInstanceExtension.cs index fddb3fcadf..0178f70dd8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignInstanceExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignInstanceExtension.cs @@ -6,6 +6,9 @@ using System.Windows.Markup; namespace ICSharpCode.WpfDesign.XamlDom { + /// + /// A class wich Implementes the DesignInstanceExtension normaly defined in the Blend Namespace + /// public class DesignInstanceExtension : MarkupExtension { public DesignInstanceExtension(Type type) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs index c85dc81dc3..fd53ea88d8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs @@ -12,7 +12,7 @@ using System.Xml; namespace ICSharpCode.WpfDesign.XamlDom { /// - /// Description of XamlXmlWriter. + /// A special XamlXmlWriter wich fixes & and " in MarkupExtensions where not correctly handeled! /// public class XamlXmlWriter : XmlWriter { From 25481b6c87dea614104ed40bf81c94509abc28f7 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Mon, 2 Mar 2015 23:39:00 +0100 Subject: [PATCH 7/7] Bugfix URI was wrong (missing "/"), when compiled with roslyn from CTP6 it did not work --- .../Project/themes/VersionedAssemblyResourceDictionary.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/VersionedAssemblyResourceDictionary.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/VersionedAssemblyResourceDictionary.cs index 24c679b196..265fede1f2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/VersionedAssemblyResourceDictionary.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/VersionedAssemblyResourceDictionary.cs @@ -31,7 +31,7 @@ namespace ICSharpCode.WpfDesign.Designer.themes static VersionedAssemblyResourceDictionary() { var nm = typeof(VersionedAssemblyResourceDictionary).Assembly.GetName(); - _uriStart = string.Format( @"{0};v{1};component/", nm.Name, nm.Version); + _uriStart = string.Format( @"/{0};v{1};component/", nm.Name, nm.Version); _subLength = "ICSharpCode.WpfDesign.Designer.".Length; }