Browse Source

New Width / Height Calculating.

If you a Control wich has a Width/height set in it's default Style, then this should be used as start size!
pull/52/head
jkuehner 12 years ago
parent
commit
4f5edf8a54
  1. 50
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  2. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  3. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

50
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -5,6 +5,13 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows; using System.Windows;
using System.Linq; using System.Linq;
using System.IO;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Xps.Serialization;
namespace ICSharpCode.WpfDesign.Designer namespace ICSharpCode.WpfDesign.Designer
{ {
@ -96,15 +103,56 @@ namespace ICSharpCode.WpfDesign.Designer
} }
} }
internal static void CreateVisualTree(this UIElement element)
{
try {
var fixedDoc = new FixedDocument();
var pageContent = new PageContent();
var fixedPage = new FixedPage();
fixedPage.Children.Add(element);
(pageContent as IAddChild).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
var f = new XpsSerializerFactory();
var w = f.CreateSerializerWriter(new MemoryStream());
w.Write(fixedDoc);
fixedPage.Children.Remove(element);
}
catch (Exception)
{ }
}
internal static Size GetDefaultSize(DesignItem createdItem) internal static Size GetDefaultSize(DesignItem createdItem)
{ {
var s = Metadata.GetDefaultSize(createdItem.ComponentType); CreateVisualTree(createdItem.View);
var s = Metadata.GetDefaultSize(createdItem.ComponentType, false);
if (double.IsNaN(s.Width) && createdItem.View.DesiredSize.Width > 0)
{
s.Width = createdItem.View.DesiredSize.Width;
}
if (double.IsNaN(s.Height) && createdItem.View.DesiredSize.Height > 0)
{
s.Height = createdItem.View.DesiredSize.Width;
}
var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true);
if (!(s.Width > 0))
s.Width = newS.Width;
if (!(s.Height > 0))
s.Height = newS.Height;
if (double.IsNaN(s.Width)) { if (double.IsNaN(s.Width)) {
s.Width = GetWidth(createdItem.View); s.Width = GetWidth(createdItem.View);
} }
if (double.IsNaN(s.Height)) { if (double.IsNaN(s.Height)) {
s.Height = GetHeight(createdItem.View); s.Height = GetHeight(createdItem.View);
} }
return s; return s;
} }

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -55,6 +55,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="ReachFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

@ -298,7 +298,7 @@ namespace ICSharpCode.WpfDesign
/// Gets the default size for new controls of the specified type, /// Gets the default size for new controls of the specified type,
/// or new Size(double.NaN, double.NaN) if no default size was registered. /// or new Size(double.NaN, double.NaN) if no default size was registered.
/// </summary> /// </summary>
public static Size GetDefaultSize(Type t) public static Size GetDefaultSize(Type t, bool checkBasetype = true)
{ {
Size s; Size s;
lock (defaultSizes) { lock (defaultSizes) {
@ -306,7 +306,7 @@ namespace ICSharpCode.WpfDesign
if (defaultSizes.TryGetValue(t, out s)) { if (defaultSizes.TryGetValue(t, out s)) {
return s; return s;
} }
t = t.BaseType; t = checkBasetype ? t.BaseType : null;
} }
} }
return new Size(double.NaN, double.NaN); return new Size(double.NaN, double.NaN);

Loading…
Cancel
Save