Browse Source

- Add tests for grid placement and tab/shift+tab navigation.

- Fix a bug in grid adorner where incorrect margins were calculated.
- clean-up in margin handle.
- change change group scheme for in-place editor to Enter for changes, Shift+Enter for newline and Esc for cancelling as suggested by Siegfried.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6398 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 15 years ago
parent
commit
d2a1fe9e83
  1. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  2. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs
  3. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/InPlaceEditor.cs
  4. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs
  5. 64
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs
  6. 102
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/FocusNavigatorTests.cs
  7. 124
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/MockFocusNavigator.cs
  8. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs
  9. 77
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs
  10. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml

@ -285,7 +285,7 @@ @@ -285,7 +285,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:InPlaceEditor}">
<TextBox Name="editor" ToolTip="Edit the Text. Press ESC key to make changes." SnapsToDevicePixels="True" Padding="{Binding Path=Padding}" FontSize="{Binding Path=FontSize}" FontFamily="{Binding Path=FontFamily}" FontStyle="{Binding Path=FontStyle}" FontStretch="{Binding Path=FontStretch}" FontWeight="{Binding Path=FontWight}" Text="{Binding Path=Bind, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" />
<TextBox Name="editor" SnapsToDevicePixels="True" Padding="{Binding Path=Padding}" FontSize="{Binding Path=FontSize}" FontFamily="{Binding Path=FontFamily}" FontStyle="{Binding Path=FontStyle}" FontStretch="{Binding Path=FontStretch}" FontWeight="{Binding Path=FontWight}" Text="{Binding Path=Bind, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" />
</ControlTemplate>
</Setter.Value>
</Setter>

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs

@ -28,8 +28,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -28,8 +28,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
bgBrush = new SolidColorBrush(Color.FromArgb(0x35, 0x1E, 0x90, 0xff));
bgBrush.Freeze();
//selBrush = new SolidColorBrush(Color.FromArgb(0xC0, 0xff, 0xb7, 0x4f));
//selBrush.Freeze();
}
readonly DesignItem gridItem;
@ -409,13 +407,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -409,13 +407,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
}
}
}
if (gridItem.Properties["Children"].CollectionElements.Count > 0) {
var operation = PlacementOperation.Start(gridItem.Properties["Children"].CollectionElements, PlacementType.Move);
foreach (var info in operation.PlacedItems) {
operation.CurrentContainerBehavior.SetPosition(info);
}
operation.Commit();
}
}
static void SplitLength(GridLength oldLength, double insertionPosition, double oldActualValue,

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/InPlaceEditor.cs

@ -60,6 +60,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -60,6 +60,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
editor = new TextBox();
editor = Template.FindName("editor", this) as TextBox; // Gets the TextBox-editor from the Template
Debug.Assert(editor != null);
editor.PreviewKeyDown+= delegate(object sender, KeyEventArgs e) {
if (e.Key == Key.Enter && (e.KeyboardDevice.Modifiers & ModifierKeys.Shift) != ModifierKeys.Shift)
{
e.Handled = true;
} };
ToolTip = "Edit the Text. Press"+Environment.NewLine+"Enter to make changes."+Environment.NewLine+"Shift+Enter to insert a newline."+Environment.NewLine+"Esc to cancel editing.";
}
/// <summary>
@ -105,6 +111,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -105,6 +111,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
}
if (textBlock != null)
textBlock.Visibility = Visibility.Visible;
Reset();
base.OnLostKeyboardFocus(e);
}
@ -115,8 +122,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -115,8 +122,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if (e.Key == Key.Escape) {
// Commit the changes to the DOM
if(e.KeyboardDevice.Modifiers != ModifierKeys.Shift) {
switch(e.Key) {
case Key.Enter:
// Commit the changes to DOM.
if(property!=null)
designItem.Properties[property].SetValue(Bind);
if(designItem.Properties[Control.FontFamilyProperty].ValueOnInstance!=editor.FontFamily)
@ -137,18 +146,40 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -137,18 +146,40 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
changeGroup = null;
this.Visibility = Visibility.Hidden;
textBlock.Visibility = Visibility.Visible;
break;
case Key.Escape:
AbortEditing();
break;
}
}else if(e.Key == Key.Enter){
editor.Text.Insert(editor.CaretIndex, Environment.NewLine);
}
}
private void Reset()
{
if (textBlock != null) {
if (property != null)
textBlock.Text = (string) designItem.Properties[property].ValueOnInstance;
textBlock.FontFamily = (System.Windows.Media.FontFamily)designItem.Properties[Control.FontFamilyProperty].ValueOnInstance;
textBlock.FontSize = (double) designItem.Properties[Control.FontSizeProperty].ValueOnInstance;
textBlock.FontStretch = (FontStretch) designItem.Properties[Control.FontStretchProperty].ValueOnInstance;
textBlock.FontStretch = (FontStretch) designItem.Properties[Control.FontStretchProperty].ValueOnInstance;
textBlock.FontWeight = (FontWeight) designItem.Properties[Control.FontWeightProperty].ValueOnInstance;
}
}
public void AbortEditing()
{
if(changeGroup!=null && _isChangeGroupOpen){
Reset();
changeGroup.Abort();
_isChangeGroupOpen=false;
}
this.Visibility= Visibility.Hidden;
if(textBlock!=null)
textBlock.Visibility=Visibility.Visible;
Reset();
}
public void StartEditing()

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs

@ -179,7 +179,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -179,7 +179,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// <summary>
/// Decides the visibllity of Handle or stub,whichever is set and hides the line-endarrow if the control is near the Grid or goes out of it.
/// </summary>
/// <param name="handleLength"></param>
public void DecideVisiblity(double handleLength)
{
if (ShouldBeVisible)

64
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -20,7 +20,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionServer(typeof(PrimarySelectionExtensionServer))]
public class MarginHandleExtension : AdornerProvider
{
//TODO : Use array to store all the handles.
private MarginHandle []_handles;
private MarginHandle _leftHandle, _topHandle, _rightHandle, _bottomHandle;
private Grid _grid;
@ -37,23 +37,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -37,23 +37,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (extendedControl.LayoutTransform.Value == Matrix.Identity && extendedControl.RenderTransform.Value == Matrix.Identity)
{
_grid = this.ExtendedItem.Parent.View as Grid;
_handles = new[]
{
_leftHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Left),
_topHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Top),
_rightHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Right),
_bottomHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Bottom),
};
foreach(var handle in _handles) {
handle.MouseLeftButtonDown += OnMouseDown;
handle.Stub.PreviewMouseLeftButtonDown += OnMouseDown;
}
_leftHandle = new MarginHandle(this.ExtendedItem, adornerPanel, HandleOrientation.Left);
_topHandle = new MarginHandle(this.ExtendedItem, adornerPanel, HandleOrientation.Top);
_rightHandle = new MarginHandle(this.ExtendedItem, adornerPanel, HandleOrientation.Right);
_bottomHandle = new MarginHandle(this.ExtendedItem, adornerPanel, HandleOrientation.Bottom);
_leftHandle.MouseLeftButtonDown += OnMouseDown;
_leftHandle.Stub.MouseLeftButtonDown += OnMouseDown;
_topHandle.MouseLeftButtonDown += OnMouseDown;
_topHandle.Stub.MouseLeftButtonDown += OnMouseDown;
_rightHandle.MouseLeftButtonDown += OnMouseDown;
_rightHandle.Stub.MouseLeftButtonDown += OnMouseDown;
_bottomHandle.MouseLeftButtonDown += OnMouseDown;
_bottomHandle.Stub.MouseLeftButtonDown += OnMouseDown;
}
if (adornerPanel != null)
@ -62,6 +58,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -62,6 +58,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
#region Change margin through handle/stub
private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
@ -216,35 +213,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -216,35 +213,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return 0;
}
#endregion
public void HideHandles()
{
if (_leftHandle != null && _topHandle != null && _rightHandle != null && _bottomHandle != null) {
_leftHandle.Visibility=Visibility.Hidden;
_leftHandle.ShouldBeVisible=false;
_topHandle.Visibility=Visibility.Hidden;
_topHandle.ShouldBeVisible=false;
_rightHandle.Visibility=Visibility.Hidden;
_rightHandle.ShouldBeVisible=false;
_bottomHandle.Visibility=Visibility.Hidden;
_bottomHandle.ShouldBeVisible=false;
if (_handles != null) {
foreach (var handle in _handles) {
handle.ShouldBeVisible = false;
handle.Visibility = Visibility.Hidden;
}
}
}
public void ShowHandles()
{
if (_leftHandle != null && _topHandle != null && _rightHandle != null && _bottomHandle != null){
_leftHandle.Visibility=Visibility.Visible;
_leftHandle.ShouldBeVisible=true;
_leftHandle.DecideVisiblity(_leftHandle.HandleLength);
_topHandle.Visibility=Visibility.Visible;
_topHandle.ShouldBeVisible=true;
_rightHandle.DecideVisiblity(_rightHandle.HandleLength);
_rightHandle.Visibility=Visibility.Visible;
_rightHandle.ShouldBeVisible=true;
_rightHandle.DecideVisiblity(_rightHandle.HandleLength);
_bottomHandle.Visibility=Visibility.Visible;
_bottomHandle.ShouldBeVisible=true;
_bottomHandle.DecideVisiblity(_bottomHandle.HandleLength);
if(_handles!=null) {
foreach(var handle in _handles) {
handle.ShouldBeVisible = true;
handle.Visibility = Visibility.Visible;
handle.DecideVisiblity(handle.HandleLength);
}
}
}
}

102
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/FocusNavigatorTests.cs

@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.Designer
{
[TestFixture]
public class FocusNavigationTests : ModelTestHelper
{
[Test]
public void SingleChildHierarchyFocusForward()
{
var grid = CreateGridContextWithDesignSurface("<Button><Button/></Button>");
var firstButton = grid.ContentProperty.CollectionElements[0];
var secondButton = firstButton.ContentProperty.Value;
var selection = grid.Services.Selection;
selection.SetSelectedComponents(new[] {grid});
var focusNavigator = new MockFocusNavigator(grid.Context);
/* Move focus forward Tab */
focusNavigator.MoveFocusForward();
Assert.AreEqual(firstButton, selection.PrimarySelection);
focusNavigator.MoveFocusForward();
Assert.AreEqual(secondButton, selection.PrimarySelection);
focusNavigator.MoveFocusForward();
Assert.AreEqual(grid, selection.PrimarySelection);
}
[Test]
public void SingleChildHierarchyFocusBack()
{
var grid = CreateGridContextWithDesignSurface("<Button><Button/></Button>");
var firstButton = grid.ContentProperty.CollectionElements[0];
var secondButton = firstButton.ContentProperty.Value;
var selection = grid.Services.Selection;
selection.SetSelectedComponents(new[] {grid});
var focusNavigator = new MockFocusNavigator(grid.Context);
/* Move focus back Shift + Tab */
focusNavigator.MoveFocusBack();
Assert.AreEqual(secondButton, selection.PrimarySelection);
focusNavigator.MoveFocusBack();
Assert.AreEqual(firstButton, selection.PrimarySelection);
}
[Test]
public void MultipleChildHierarchyFocusForward()
{
var grid = CreateGridContextWithDesignSurface("<Button/><Grid><Button/></Grid>");
var firstButton = grid.ContentProperty.CollectionElements[0];
var innerGrid = grid.ContentProperty.CollectionElements[1];
var innerGridButton = innerGrid.ContentProperty.CollectionElements[0];
var selection = grid.Services.Selection;
selection.SetSelectedComponents(new[] { grid });
var focusNavigator = new MockFocusNavigator(grid.Context);
/* Move focus forward Tab */
focusNavigator.MoveFocusForward();
Assert.AreEqual(firstButton, selection.PrimarySelection);
focusNavigator.MoveFocusForward();
Assert.AreEqual(innerGrid, selection.PrimarySelection);
focusNavigator.MoveFocusForward();
Assert.AreEqual(innerGridButton, selection.PrimarySelection);
focusNavigator.MoveFocusForward();
Assert.AreEqual(grid, selection.PrimarySelection);
}
[Test]
public void MultipleChildHierarchyFocusBack()
{
var grid = CreateGridContextWithDesignSurface("<Button/><Grid><Button/></Grid>");
var firstButton = grid.ContentProperty.CollectionElements[0];
var innerGrid = grid.ContentProperty.CollectionElements[1];
var innerGridButton = innerGrid.ContentProperty.CollectionElements[0];
var selection = grid.Services.Selection;
selection.SetSelectedComponents(new[] { grid });
var focusNavigator = new MockFocusNavigator(grid.Context);
/* Move focus back Shift + Tab */
focusNavigator.MoveFocusBack();
Assert.AreEqual(innerGridButton, selection.PrimarySelection);
focusNavigator.MoveFocusBack();
Assert.AreEqual(innerGrid, selection.PrimarySelection);
focusNavigator.MoveFocusBack();
Assert.AreEqual(firstButton, selection.PrimarySelection);
focusNavigator.MoveFocusBack();
Assert.AreEqual(grid, selection.PrimarySelection);
focusNavigator.MoveFocusBack();
Assert.AreEqual(innerGridButton, selection.PrimarySelection);
}
}
}

124
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/MockFocusNavigator.cs

@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Linq;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.WpfDesign.Tests.Designer
{
internal class MockFocusNavigator
{
private readonly DesignContext _context;
internal MockFocusNavigator(DesignContext context)
{
_context = context;
}
/// <summary>
/// Moves the Focus down the tree.
/// </summary>
internal void MoveFocusForward()
{
ISelectionService selection = _context.Services.Selection;
DesignItem item = selection.PrimarySelection;
selection.SetSelectedComponents(selection.SelectedItems, SelectionTypes.Remove);
if (item != GetLastElement()) {
if (item.ContentProperty != null) {
if (item.ContentProperty.IsCollection) {
if (item.ContentProperty.CollectionElements.Count != 0) {
if (ModelTools.CanSelectComponent(item.ContentProperty.CollectionElements.First()))
selection.SetSelectedComponents(new DesignItem[] {item.ContentProperty.CollectionElements.First()}, SelectionTypes.Primary);
else
SelectNextInPeers(item);
} else
SelectNextInPeers(item);
} else if (item.ContentProperty.Value != null) {
if (ModelTools.CanSelectComponent(item.ContentProperty.Value))
selection.SetSelectedComponents(new DesignItem[] {item.ContentProperty.Value}, SelectionTypes.Primary);
else
SelectNextInPeers(item);
} else {
SelectNextInPeers(item);
}
} else {
SelectNextInPeers(item);
}
} else {
//if the element was last element move focus to the root element to keep a focus cycle.
selection.SetSelectedComponents(new DesignItem[] {_context.RootItem}, SelectionTypes.Primary);
}
}
/// <summary>
/// Moves focus up-the-tree.
/// </summary>
internal void MoveFocusBack()
{
ISelectionService selection = _context.Services.Selection;
DesignItem item = selection.PrimarySelection;
if (item != _context.RootItem) {
if (item.Parent != null && item.Parent.ContentProperty.IsCollection) {
int index = item.Parent.ContentProperty.CollectionElements.IndexOf(item);
if (index != 0) {
if (ModelTools.CanSelectComponent(item.Parent.ContentProperty.CollectionElements.ElementAt(index - 1)))
selection.SetSelectedComponents(new DesignItem[] {item.Parent.ContentProperty.CollectionElements.ElementAt(index - 1)}, SelectionTypes.Primary);
} else {
if (ModelTools.CanSelectComponent(item.Parent))
selection.SetSelectedComponents(new DesignItem[] {item.Parent}, SelectionTypes.Primary);
}
} else {
if (ModelTools.CanSelectComponent(item.Parent))
selection.SetSelectedComponents(new DesignItem[] {item.Parent}, SelectionTypes.Primary);
}
} else {
// if the element was root item move focus again to the last element.
selection.SetSelectedComponents(new DesignItem[] {GetLastElement()}, SelectionTypes.Primary);
}
}
/// <summary>
/// Gets the last element in the element hierarchy.
/// </summary>
private DesignItem GetLastElement()
{
DesignItem item = _context.RootItem;
while (item != null && item.ContentProperty != null) {
if (item.ContentProperty.IsCollection) {
if (item.ContentProperty.CollectionElements.Count != 0) {
if (ModelTools.CanSelectComponent(item.ContentProperty.CollectionElements.Last()))
item = item.ContentProperty.CollectionElements.Last();
else
break;
} else
break;
} else {
if (item.ContentProperty.Value != null)
item = item.ContentProperty.Value;
else
break;
}
}
return item;
}
/// <summary>
/// Select the next element in the element collection if <paramref name="item"/> parent's had it's content property as collection.
/// </summary>
private void SelectNextInPeers(DesignItem item)
{
ISelectionService selection = _context.Services.Selection;
if (item.Parent != null && item.Parent.ContentProperty != null) {
if (item.Parent.ContentProperty.IsCollection) {
int index = item.Parent.ContentProperty.CollectionElements.IndexOf(item);
if (index != item.Parent.ContentProperty.CollectionElements.Count)
selection.SetSelectedComponents(new DesignItem[] {item.Parent.ContentProperty.CollectionElements.ElementAt(index + 1)}, SelectionTypes.Primary);
}
}
}
}
}

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs

@ -86,6 +86,16 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -86,6 +86,16 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
return gridChild;
}
protected DesignItem CreateGridContextWithDesignSurface(string xaml)
{
var surface = new DesignSurface();
var xamlWithGrid=@"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
" + xaml + "</Grid>";
surface.LoadDesigner(new XmlTextReader(new StringReader(xamlWithGrid)), new XamlLoadSettings());
Assert.IsNotNull(surface.DesignContext.RootItem);
return surface.DesignContext.RootItem;
}
static string ItemIdentity(DesignItem item)
{
return item.ComponentType.Name + " (" + item.GetHashCode() + ")";

77
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Windows;
using System.Windows.Controls;
using NUnit.Framework;
using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Designer;
@ -41,7 +42,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -41,7 +42,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
}
[Test]
[Ignore] //Currently bounds calculated using visuals
[Ignore("Currently bounds calculated using visuals")]
public void MoveFixedWidthButton()
{
DesignItem button = CreateCanvasContext("<Button Width='100' Height='200'/>");
@ -56,5 +57,79 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -56,5 +57,79 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
Move(new Vector(50, 25), button);
AssertCanvasDesignerOutput(@"<Button Canvas.Left=""50"" Canvas.Top=""25"" />", button.Context);
}
#region Grid Placement Tests
private DesignItem _buttonInGridWithAutoSize;
private DesignItem _buttonIsGridWithFixedSize;
[TestFixtureSetUp]
public void Intialize()
{
_buttonInGridWithAutoSize=CreateGridContext("<Button/>");
Move(new Vector(50,25),_buttonInGridWithAutoSize);
_buttonIsGridWithFixedSize=CreateGridContext("<Button HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" Width=\"50\" Height=\"50\"/>");
Move(new Vector(50,25),_buttonIsGridWithFixedSize);
}
[Test]
public void AssertAlignmentsForAutoSize()
{
Assert.AreEqual(HorizontalAlignment.Stretch,_buttonInGridWithAutoSize.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance);
Assert.AreEqual(VerticalAlignment.Stretch,_buttonInGridWithAutoSize.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance);
}
[Test]
public void AssertAlignmentForFixedSize()
{
Assert.AreEqual(HorizontalAlignment.Left,_buttonIsGridWithFixedSize.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance);
Assert.AreEqual(VerticalAlignment.Top,_buttonIsGridWithFixedSize.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance);
}
[Test]
public void AssertMarginForAutoSize()
{
Assert.AreEqual(new Thickness(50,25,-50,-25),_buttonInGridWithAutoSize.Properties[FrameworkElement.MarginProperty].ValueOnInstance);
}
[Test]
public void AssertMarginForFixedSize()
{
Assert.AreEqual(new Thickness(50,25,0,0),_buttonIsGridWithFixedSize.Properties[FrameworkElement.MarginProperty].ValueOnInstance);
}
[Test]
public void AssertRowColumnForAutoSize()
{
Assert.AreEqual(0,_buttonInGridWithAutoSize.Properties.GetAttachedProperty(Grid.RowProperty).ValueOnInstance);
Assert.AreEqual(1,_buttonInGridWithAutoSize.Properties.GetAttachedProperty(Grid.RowSpanProperty).ValueOnInstance);
Assert.AreEqual(0,_buttonInGridWithAutoSize.Properties.GetAttachedProperty(Grid.ColumnProperty).ValueOnInstance);
Assert.AreEqual(1,_buttonInGridWithAutoSize.Properties.GetAttachedProperty(Grid.ColumnSpanProperty).ValueOnInstance);
}
[Test]
public void AssetRowColumnForFixedSize()
{
Assert.AreEqual(0, _buttonIsGridWithFixedSize.Properties.GetAttachedProperty(Grid.RowProperty).ValueOnInstance);
Assert.AreEqual(1, _buttonIsGridWithFixedSize.Properties.GetAttachedProperty(Grid.RowSpanProperty).ValueOnInstance);
Assert.AreEqual(0, _buttonIsGridWithFixedSize.Properties.GetAttachedProperty(Grid.ColumnProperty).ValueOnInstance);
Assert.AreEqual(1, _buttonIsGridWithFixedSize.Properties.GetAttachedProperty(Grid.ColumnSpanProperty).ValueOnInstance);
}
[Test]
public void AssertSizeForAutoSize()
{
Assert.AreEqual(double.NaN,_buttonInGridWithAutoSize.Properties[FrameworkElement.HeightProperty].ValueOnInstance);
Assert.AreEqual(double.NaN,_buttonInGridWithAutoSize.Properties[FrameworkElement.WidthProperty].ValueOnInstance);
}
[Test]
[Ignore("Bounds calculated using Visuals")]
public void AssertSizeForFixedSize()
{
Assert.AreEqual(50,_buttonIsGridWithFixedSize.Properties[FrameworkElement.HeightProperty].ValueOnInstance);
Assert.AreEqual(50,_buttonIsGridWithFixedSize.Properties[FrameworkElement.WidthProperty].ValueOnInstance);
}
#endregion
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -55,7 +55,9 @@ @@ -55,7 +55,9 @@
<Link>GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Designer\FocusNavigatorTests.cs" />
<Compile Include="Designer\MarginHandleTests.cs" />
<Compile Include="Designer\MockFocusNavigator.cs" />
<Compile Include="Designer\ModelTestHelper.cs" />
<Compile Include="Designer\ModelTests.cs" />
<Compile Include="Designer\PlacementTests.cs" />

Loading…
Cancel
Save