Skip to content

Commit

Permalink
Merge pull request icsharpcode#584 from jogibear9988/master
Browse files Browse the repository at this point in the history
WPF Designer multiple Fixes
  • Loading branch information
siegfriedpammer committed Oct 31, 2014
2 parents 733494b + b7d36b3 commit 9f1d12b
Show file tree
Hide file tree
Showing 82 changed files with 2,815 additions and 348 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ICSharpCode.WpfDesign.Designer
{
public enum ArrangeDirection
{
Top,
VerticalMiddle,
Bottom,
Left,
HorizontalMiddle,
Right,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public static void Register()
Metadata.AddPopularProperty(TreeViewItem.IsSelectedProperty);
Metadata.AddPopularProperty(Border.PaddingProperty);
Metadata.AddPopularProperty(Shape.StretchProperty);

Metadata.AddPopularProperty(Control.VerticalContentAlignmentProperty);
Metadata.AddPopularProperty(Control.HorizontalContentAlignmentProperty);

Metadata.AddPopularProperty(Grid.RowProperty);
Metadata.AddPopularProperty(Grid.RowSpanProperty);
Metadata.AddPopularProperty(Grid.ColumnProperty);
Expand Down Expand Up @@ -230,14 +232,14 @@ public static void Register()
Metadata.AddPopularControl(typeof(Border));
Metadata.AddPopularControl(typeof(Canvas));
Metadata.AddPopularControl(typeof(CheckBox));
Metadata.AddPopularControl(typeof(ComboBox));
Metadata.AddPopularControl(typeof(ComboBox));
Metadata.AddPopularControl(typeof(DataGrid));
Metadata.AddPopularControl(typeof(DockPanel));
Metadata.AddPopularControl(typeof(Expander));
Metadata.AddPopularControl(typeof(Grid));
Metadata.AddPopularControl(typeof(GroupBox));
Metadata.AddPopularControl(typeof(Image));
Metadata.AddPopularControl(typeof(InkCanvas));
Metadata.AddPopularControl(typeof(Image));
Metadata.AddPopularControl(typeof(InkCanvas));
Metadata.AddPopularControl(typeof(Label));
Metadata.AddPopularControl(typeof(ListBox));
Metadata.AddPopularControl(typeof(ListView));
Expand All @@ -249,7 +251,7 @@ public static void Register()
Metadata.AddPopularControl(typeof(RichTextBox));
Metadata.AddPopularControl(typeof(StackPanel));
Metadata.AddPopularControl(typeof(ScrollViewer));
Metadata.AddPopularControl(typeof(Slider));
Metadata.AddPopularControl(typeof(Slider));
Metadata.AddPopularControl(typeof(TabControl));
Metadata.AddPopularControl(typeof(TextBlock));
Metadata.AddPopularControl(typeof(TextBox));
Expand All @@ -259,28 +261,30 @@ public static void Register()
Metadata.AddPopularControl(typeof(Viewport3D));
Metadata.AddPopularControl(typeof(WrapPanel));

Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100));
Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20));
Metadata.AddDefaultSize(typeof(Button), new Size(75, 23));
//Basic Metadata Size of double.NaN, means no Size should be set.
Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN));
Metadata.AddDefaultSize(typeof(CheckBox), new Size(double.NaN, double.NaN));
Metadata.AddDefaultSize(typeof(Image), new Size(double.NaN, double.NaN));

Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100));
Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20));
Metadata.AddDefaultSize(typeof(Button), new Size(75, 23));
Metadata.AddDefaultSize(typeof(ToggleButton), new Size(75, 23));

var s1 = new Size(120, 20);
Metadata.AddDefaultSize(typeof(Slider), s1);
Metadata.AddDefaultSize(typeof(TextBox), s1);
Metadata.AddDefaultSize(typeof(PasswordBox), s1);
Metadata.AddDefaultSize(typeof(ComboBox), s1);
Metadata.AddDefaultSize(typeof(ProgressBar), s1);
Metadata.AddDefaultSize(typeof(Slider), new Size(120, 20));
Metadata.AddDefaultSize(typeof(TextBox), new Size(120, 20));
Metadata.AddDefaultSize(typeof(PasswordBox), new Size(120, 20));
Metadata.AddDefaultSize(typeof(ComboBox), new Size(120, 20));
Metadata.AddDefaultSize(typeof(ProgressBar), new Size(120, 20));

Metadata.AddDefaultSize(typeof(ToolBar), s1);
Metadata.AddDefaultSize(typeof(Menu), s1);

var s2=new Size(120,120);
Metadata.AddDefaultSize(typeof(InkCanvas),s2);
Metadata.AddDefaultSize(typeof(Image),s2);
Metadata.AddDefaultSize(typeof(TreeView),s2);

var s3=new Size(130,120);
Metadata.AddDefaultSize(typeof(Label),s3);
Metadata.AddDefaultSize(typeof(Expander),s3);
Metadata.AddDefaultSize(typeof(ToolBar), new Size(120, 20));
Metadata.AddDefaultSize(typeof(Menu), new Size(120, 20));

Metadata.AddDefaultSize(typeof(InkCanvas), new Size(120, 120));
Metadata.AddDefaultSize(typeof(TreeView), new Size(120, 120));

Metadata.AddDefaultSize(typeof(Label), new Size(130, 120));
Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// <summary>
/// A control that displays adorner panels.
/// </summary>
sealed class AdornerLayer : Panel
public sealed class AdornerLayer : Panel
{
#region AdornerPanelCollection
internal sealed class AdornerPanelCollection : ICollection<AdornerPanel>, IReadOnlyCollection<AdornerPanel>
Expand Down Expand Up @@ -218,13 +218,23 @@ protected override Size MeasureOverride(Size availableSize)
}
return new Size(0, 0);
}

protected override Size ArrangeOverride(Size finalSize)
{
foreach (AdornerPanel adorner in this.Children) {
if (adorner.AdornedElement.IsDescendantOf(_designPanel)) {
adorner.RenderTransform = (Transform)adorner.AdornedElement.TransformToAncestor(_designPanel);
foreach (AdornerPanel adorner in this.Children) {
if (adorner.AdornedElement.IsDescendantOf(_designPanel))
{
var rt = (MatrixTransform) adorner.AdornedElement.TransformToAncestor(_designPanel);
if (adorner.AdornedDesignItem != null && adorner.AdornedDesignItem.Parent != null && adorner.AdornedDesignItem.Parent.View is Canvas && adorner.AdornedElement.RenderSize.Height == 0 && adorner.AdornedElement.RenderSize.Width == 0)
{
var xOffset = rt.Matrix.OffsetX - (((FrameworkElement)adorner.AdornedElement).Width / 2);
var yOffset = rt.Matrix.OffsetY - (((FrameworkElement)adorner.AdornedElement).Height / 2);
rt = new MatrixTransform(new Matrix(rt.Matrix.M11, rt.Matrix.M12, rt.Matrix.M21, rt.Matrix.M22, xOffset, yOffset));
}

adorner.RenderTransform = rt;
}

adorner.Arrange(new Rect(new Point(0, 0), adorner.DesiredSize));
}
return finalSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void BindAndPlaceHandle()
if (double.IsNaN(wr))
{
wr = (double) rightDescriptor.GetValue(adornedControl);
wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr);
wr = canvas.ActualWidth - (PlacementOperation.GetRealElementSize(adornedControl).Width + wr);
}
else
{
Expand All @@ -167,7 +167,7 @@ void BindAndPlaceHandle()
if (double.IsNaN(wr))
{
wr = (double)bottomDescriptor.GetValue(adornedControl);
wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr);
wr = canvas.ActualHeight - (PlacementOperation.GetRealElementSize(adornedControl).Height + wr);
}
else
{
Expand All @@ -188,7 +188,7 @@ void BindAndPlaceHandle()
if (double.IsNaN(wr))
{
wr = (double) leftDescriptor.GetValue(adornedControl);
wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr);
wr = canvas.ActualWidth - (PlacementOperation.GetRealElementSize(adornedControl).Width + wr);
}
else
{
Expand All @@ -209,7 +209,7 @@ void BindAndPlaceHandle()
if (double.IsNaN(wr))
{
wr = (double)topDescriptor.GetValue(adornedControl);
wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr);
wr = canvas.ActualHeight - (PlacementOperation.GetRealElementSize(adornedControl).Height + wr);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,16 @@
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Path SnapsToDevicePixels="True" Grid.Row="0" Stroke="#AC0000" StrokeThickness="1.0" Data="M0,0 L1,0 M0.75,0 L0.75,1" Stretch="Fill" />
<TextBlock Text="{Binding Path=ActualHeight, Converter={x:Static Converters:FormatDoubleConverter.Instance}}" HorizontalAlignment="Center" Margin="8,0,0,1" Padding="1,1,1,1" FontSize="10" Grid.Row="1">
<TextBlock HorizontalAlignment="Center" Margin="8,0,0,1" Padding="1,1,1,1" FontSize="10" Grid.Row="1">
<TextBlock.Text>
<MultiBinding Converter="{x:Static Converters:ControlToRealHeightConverter.Instance}" StringFormat="0">
<MultiBinding.Bindings>
<Binding />
<Binding Path="ActualHeight" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Height" UpdateSourceTrigger="PropertyChanged" />
</MultiBinding.Bindings>
</MultiBinding>
</TextBlock.Text>
<TextBlock.LayoutTransform>
<RotateTransform Angle="270" CenterX="0.5" CenterY="0.5" />
</TextBlock.LayoutTransform>
Expand All @@ -355,7 +364,17 @@
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<Path Grid.Column="0" Stroke="#AC0000" StrokeThickness="1" Data="M0,0 L0,1 M0,0.75 L1,0.75" Stretch="Fill" SnapsToDevicePixels="True" />
<TextBlock Text="{Binding Path=ActualWidth, Converter={x:Static Converters:FormatDoubleConverter.Instance}}" HorizontalAlignment="Center" Margin="0,8,0,0" Padding="1,1,1,1" FontSize="10" Grid.Column="1" />
<TextBlock HorizontalAlignment="Center" Margin="0,8,0,0" Padding="1,1,1,1" FontSize="10" Grid.Column="1">
<TextBlock.Text>
<MultiBinding Converter="{x:Static Converters:ControlToRealWidthConverter.Instance}" StringFormat="0">
<MultiBinding.Bindings>
<Binding />
<Binding Path="ActualWidth" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Width" UpdateSourceTrigger="PropertyChanged" />
</MultiBinding.Bindings>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<Path Grid.Column="2" Stroke="#AC0000" StrokeThickness="1" Data="M0,0.75 L3,0.75 M3,0 L3,1 " Stretch="Fill" SnapsToDevicePixels="True" />
</Grid>
</ControlTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ protected override Size ArrangeOverride(Size arrangeBounds)
AdornerPanel parent = this.Parent as AdornerPanel;
if (parent != null && parent.AdornedElement != null) {
if (checkWidth)
this.ResizeThumbVisible = parent.AdornedElement.RenderSize.Width > 14;
this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14;
else if (checkHeight)
this.ResizeThumbVisible = parent.AdornedElement.RenderSize.Height > 14;
this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14;
}
return base.ArrangeOverride(arrangeBounds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,38 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
return value;
}
}

public class FormatDoubleConverter : IValueConverter

public class ControlToRealWidthConverter : IMultiValueConverter
{
public static readonly ControlToRealWidthConverter Instance = new ControlToRealWidthConverter();

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return PlacementOperation.GetRealElementSize((UIElement)values[0]).Width;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class ControlToRealHeightConverter : IMultiValueConverter
{
public static readonly ControlToRealHeightConverter Instance = new ControlToRealHeightConverter();

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return PlacementOperation.GetRealElementSize((UIElement)values[0]).Height;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class FormatDoubleConverter : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly FormatDoubleConverter Instance=new FormatDoubleConverter();
Expand Down
Loading

0 comments on commit 9f1d12b

Please sign in to comment.