From 4011b68f35918f1722caef60b647906db2304cda Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Jul 2013 17:40:06 +0200 Subject: [PATCH] Fix Default Initializer - Fix Problems with nested TextBlocks (Text was removed when it was set) - Fix that not every ContentControl can have a String as Content (for Example Zoom Control in Extended WPF Toolkit) --- .../Project/Extensions/Initializers.cs | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs index d8d2405046..9d97f7f995 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs @@ -15,13 +15,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers { public override void InitializeDefaults(DesignItem item) { - DesignItemProperty contentProperty = item.Properties["Content"]; - if (contentProperty.ValueOnInstance == null) { - contentProperty.SetValue(item.ComponentType.Name); + //Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit) + if (item.Component is Button) + { + DesignItemProperty contentProperty = item.Properties["Content"]; + if (contentProperty.ValueOnInstance == null) + { + contentProperty.SetValue(item.ComponentType.Name); + } } + + DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; + if (verticalAlignmentProperty.ValueOnInstance == null) + { + verticalAlignmentProperty.SetValue(VerticalAlignment.Center); + } + + DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"]; + if (horizontalAlignmentProperty.ValueOnInstance == null) + { + horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center); + } } } + [ExtensionFor(typeof(TextBlock))] + public class TextBlockInitializer : DefaultInitializer + { + public override void InitializeDefaults(DesignItem item) + { + DesignItemProperty textProperty = item.Properties["Text"]; + if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "") + { + textProperty.SetValue(item.ComponentType.Name); + } + + DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; + if (verticalAlignmentProperty.ValueOnInstance == null) + { + verticalAlignmentProperty.SetValue(VerticalAlignment.Center); + } + + DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"]; + if (horizontalAlignmentProperty.ValueOnInstance == null) + { + horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center); + } + } + } + [ExtensionFor(typeof(HeaderedContentControl), OverrideExtension = typeof(ContentControlInitializer))] public class HeaderedContentControlInitializer : DefaultInitializer {