mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-13 20:56:35 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using Fluent.Tests.Helper;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class BackstageTests
|
||||
{
|
||||
/// <summary>
|
||||
/// This test ensures that the <see cref="BackstageAdorner"/> is destroyed as soon as the <see cref="Backstage"/> is unloaded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Adorner_should_be_destroyed_on_unload()
|
||||
{
|
||||
var backstage = new Backstage
|
||||
{
|
||||
Content = new Button()
|
||||
};
|
||||
|
||||
using (var window = new TestRibbonWindow(backstage))
|
||||
{
|
||||
Assert.That(backstage.IsLoaded, Is.True);
|
||||
|
||||
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Null);
|
||||
|
||||
backstage.IsOpen = true;
|
||||
|
||||
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Not.Null);
|
||||
|
||||
backstage.IsOpen = false;
|
||||
|
||||
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Not.Null);
|
||||
|
||||
window.Content = null;
|
||||
|
||||
UIHelper.DoEvents();
|
||||
|
||||
Assert.That(backstage.GetFieldValue<object>("adorner"), Is.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class InRibbonGalleryTests
|
||||
{
|
||||
[Test]
|
||||
public void Opening_DropDown_Should_Not_Throw_When_GalleryPanel_Has_No_Width()
|
||||
{
|
||||
var control = new InRibbonGallery
|
||||
{
|
||||
Width = 10,
|
||||
Height = 30
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(control))
|
||||
{
|
||||
Assert.That(() => control.IsDropDownOpen = true, Throws.Nothing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class QuickAccessToolBarTests
|
||||
{
|
||||
[Test]
|
||||
public void TestDefaultKeyTips()
|
||||
{
|
||||
var toolbar = new QuickAccessToolBar();
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
toolbar.Items.Add(new UIElement());
|
||||
}
|
||||
|
||||
TestDefaultKeyTips(toolbar);
|
||||
}
|
||||
|
||||
private static void TestDefaultKeyTips(QuickAccessToolBar toolbar)
|
||||
{
|
||||
var keyTips = toolbar.Items.Select(KeyTip.GetKeys);
|
||||
var expectedKeyTips = new[]
|
||||
{
|
||||
"1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||
"09", "08", "07", "06", "05", "04", "03", "02", "01",
|
||||
"0A", "0B", "0C", "0D", "0E", "0F", "0G", "0H", "0I", "0J", "0K", "0L"
|
||||
};
|
||||
|
||||
Assert.That(keyTips, Is.EquivalentTo(expectedKeyTips));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCustomKeyTips()
|
||||
{
|
||||
var toolbar = new QuickAccessToolBar
|
||||
{
|
||||
UpdateKeyTipsAction = quickAccessToolBar =>
|
||||
{
|
||||
for (var i = 0; i < quickAccessToolBar.Items.Count; i++)
|
||||
{
|
||||
KeyTip.SetKeys(quickAccessToolBar.Items[i], (i + 1).ToString("00", CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
toolbar.Items.Add(new UIElement());
|
||||
}
|
||||
|
||||
var keyTips = toolbar.Items.Select(KeyTip.GetKeys);
|
||||
var expectedKeyTips = new[]
|
||||
{
|
||||
"01", "02", "03", "04", "05", "06", "07", "08", "09",
|
||||
"10", "11", "12", "13", "14", "15", "16", "17", "18",
|
||||
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"
|
||||
};
|
||||
|
||||
Assert.That(keyTips, Is.EquivalentTo(expectedKeyTips));
|
||||
|
||||
toolbar.UpdateKeyTipsAction = null;
|
||||
|
||||
TestDefaultKeyTips(toolbar);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using Fluent.Tests.Helper;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class RibbonGroupBoxTests
|
||||
{
|
||||
[Test]
|
||||
public void Size_Should_Change_On_Group_State_Change_When_Items_Are_Bound()
|
||||
{
|
||||
var items = new List<ItemViewModel>
|
||||
{
|
||||
new ItemViewModel()
|
||||
};
|
||||
|
||||
var ribbonGroupBox = new RibbonGroupBox
|
||||
{
|
||||
ItemsSource = items,
|
||||
ItemTemplate = CreateDataTemplateForItemViewModel()
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(ribbonGroupBox))
|
||||
{
|
||||
{
|
||||
{
|
||||
ribbonGroupBox.State = RibbonGroupBoxState.Small;
|
||||
UIHelper.DoEvents();
|
||||
}
|
||||
|
||||
Assert.That(items.First().ControlSize, Is.EqualTo(RibbonControlSize.Small));
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
ribbonGroupBox.State = RibbonGroupBoxState.Middle;
|
||||
UIHelper.DoEvents();
|
||||
}
|
||||
|
||||
Assert.That(items.First().ControlSize, Is.EqualTo(RibbonControlSize.Middle));
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
ribbonGroupBox.State = RibbonGroupBoxState.Large;
|
||||
UIHelper.DoEvents();
|
||||
}
|
||||
|
||||
Assert.That(items.First().ControlSize, Is.EqualTo(RibbonControlSize.Large));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Size_Should_Change_On_Group_State_Change_When_Items_Are_Ribbon_Controls()
|
||||
{
|
||||
var ribbonGroupBox = new RibbonGroupBox();
|
||||
|
||||
ribbonGroupBox.Items.Add(new Fluent.Button());
|
||||
|
||||
using (new TestRibbonWindow(ribbonGroupBox))
|
||||
{
|
||||
{
|
||||
{
|
||||
ribbonGroupBox.State = RibbonGroupBoxState.Small;
|
||||
UIHelper.DoEvents();
|
||||
}
|
||||
|
||||
Assert.That(ribbonGroupBox.Items.OfType<Fluent.Button>().First().Size, Is.EqualTo(RibbonControlSize.Small));
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
ribbonGroupBox.State = RibbonGroupBoxState.Middle;
|
||||
UIHelper.DoEvents();
|
||||
}
|
||||
|
||||
Assert.That(ribbonGroupBox.Items.OfType<Fluent.Button>().First().Size, Is.EqualTo(RibbonControlSize.Middle));
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
ribbonGroupBox.State = RibbonGroupBoxState.Large;
|
||||
UIHelper.DoEvents();
|
||||
}
|
||||
|
||||
Assert.That(ribbonGroupBox.Items.OfType<Fluent.Button>().First().Size, Is.EqualTo(RibbonControlSize.Large));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DataTemplate CreateDataTemplateForItemViewModel()
|
||||
{
|
||||
var dataTemplate = new DataTemplate(typeof(ItemViewModel));
|
||||
|
||||
var factory = new FrameworkElementFactory(typeof(Fluent.Button));
|
||||
factory.SetBinding(RibbonProperties.SizeProperty, new Binding(nameof(ItemViewModel.ControlSize)) { Mode = BindingMode.TwoWay });
|
||||
|
||||
//set the visual tree of the data template
|
||||
dataTemplate.VisualTree = factory;
|
||||
|
||||
return dataTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemViewModel
|
||||
{
|
||||
public RibbonControlSize ControlSize { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using Fluent.Tests.Helper;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
using ComboBox = Fluent.ComboBox;
|
||||
using TextBox = Fluent.TextBox;
|
||||
|
||||
[TestFixture]
|
||||
public class RibbonGroupBoxWrapPanelTests
|
||||
{
|
||||
private static RibbonGroupBox CreateRibbonGroupBox(bool isSharedSizeScope)
|
||||
{
|
||||
var ribbonGroupBox = new RibbonGroupBox
|
||||
{
|
||||
Header = "Test-Header",
|
||||
Height = 94
|
||||
};
|
||||
Grid.SetIsSharedSizeScope(ribbonGroupBox, isSharedSizeScope);
|
||||
|
||||
AddControls(ribbonGroupBox.Items);
|
||||
|
||||
return ribbonGroupBox;
|
||||
}
|
||||
|
||||
private static void AddControls(IList items)
|
||||
{
|
||||
items.Add(new TextBox
|
||||
{
|
||||
Header = "First Column (1)"
|
||||
});
|
||||
|
||||
items.Add(new ComboBox
|
||||
{
|
||||
Header = "First Column (2)"
|
||||
});
|
||||
|
||||
items.Add(new Spinner
|
||||
{
|
||||
Header = "First Column Long"
|
||||
});
|
||||
|
||||
items.Add(new ComboBox
|
||||
{
|
||||
Header = "Second Column (1)"
|
||||
});
|
||||
|
||||
items.Add(new ComboBox
|
||||
{
|
||||
Header = "Second Column (2) Long Long"
|
||||
});
|
||||
|
||||
items.Add(new Spinner
|
||||
{
|
||||
Header = "Second Column"
|
||||
});
|
||||
}
|
||||
|
||||
private static TextBlock GetHeaderTextBlock(Control control)
|
||||
{
|
||||
return (TextBlock)control.Template.FindName("headerTextBlock", control);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SharedSizeGroupName_Should_Be_Possible_To_Opt_Out()
|
||||
{
|
||||
var ribbonGroupBox = CreateRibbonGroupBox(true);
|
||||
|
||||
using (new TestRibbonWindow(ribbonGroupBox))
|
||||
{
|
||||
var controls = ribbonGroupBox.Items.Cast<Control>().ToList();
|
||||
|
||||
RibbonGroupBoxWrapPanel.SetExcludeFromSharedSize(controls[1], true);
|
||||
RibbonGroupBoxWrapPanel.SetExcludeFromSharedSize(controls[5], true);
|
||||
|
||||
UIHelper.DoEvents();
|
||||
|
||||
// First column
|
||||
{
|
||||
var columnControls = controls.Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
|
||||
{
|
||||
"SharedSizeGroup_Column_1",
|
||||
null,
|
||||
"SharedSizeGroup_Column_1"
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
96,
|
||||
84,
|
||||
96
|
||||
}));
|
||||
}
|
||||
|
||||
// Second column
|
||||
{
|
||||
var columnControls = controls.Skip(3).Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
|
||||
{
|
||||
"SharedSizeGroup_Column_2",
|
||||
"SharedSizeGroup_Column_2",
|
||||
null
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
160,
|
||||
160,
|
||||
84
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SharedSizeGroupName_Should_Be_Set_If_RibbonGroupBox_Is_SharedSizeScope()
|
||||
{
|
||||
var ribbonGroupBox = CreateRibbonGroupBox(true);
|
||||
|
||||
using (new TestRibbonWindow(ribbonGroupBox))
|
||||
{
|
||||
var controls = ribbonGroupBox.Items.Cast<Control>().ToList();
|
||||
|
||||
// First column
|
||||
{
|
||||
var columnControls = controls.Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
|
||||
{
|
||||
"SharedSizeGroup_Column_1",
|
||||
"SharedSizeGroup_Column_1",
|
||||
"SharedSizeGroup_Column_1"
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
96,
|
||||
96,
|
||||
96
|
||||
}));
|
||||
}
|
||||
|
||||
// Second column
|
||||
{
|
||||
var columnControls = controls.Skip(3).Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new[]
|
||||
{
|
||||
"SharedSizeGroup_Column_2",
|
||||
"SharedSizeGroup_Column_2",
|
||||
"SharedSizeGroup_Column_2"
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
160,
|
||||
160,
|
||||
160
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SharedSizeGroupName_Should_Not_Be_Set_If_RibbonGroupBox_Is_Not_SharedSizeScope()
|
||||
{
|
||||
var ribbonGroupBox = CreateRibbonGroupBox(false);
|
||||
|
||||
using (new TestRibbonWindow(ribbonGroupBox))
|
||||
{
|
||||
var controls = ribbonGroupBox.Items.Cast<Control>().ToList();
|
||||
|
||||
// First column
|
||||
{
|
||||
var columnControls = controls.Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
|
||||
{
|
||||
null,
|
||||
null,
|
||||
null
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
84,
|
||||
84,
|
||||
96
|
||||
}));
|
||||
}
|
||||
|
||||
// Second column
|
||||
{
|
||||
var columnControls = controls.Skip(3).Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
|
||||
{
|
||||
null,
|
||||
null,
|
||||
null
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
101,
|
||||
160,
|
||||
84
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for not working because we have to test for <see cref="Grid.IsSharedSizeScopeProperty" /> on parent
|
||||
/// <see cref="RibbonGroupBox" />.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void SharedSizeGroupName_Should_Not_Work_Without_RibbonGroupBox()
|
||||
{
|
||||
var ribbonGroupBoxWrapPanel = new RibbonGroupBoxWrapPanel
|
||||
{
|
||||
Height = 94
|
||||
};
|
||||
|
||||
AddControls(ribbonGroupBoxWrapPanel.Children);
|
||||
|
||||
using (new TestRibbonWindow(ribbonGroupBoxWrapPanel))
|
||||
{
|
||||
var controls = ribbonGroupBoxWrapPanel.Children.Cast<Control>().ToList();
|
||||
|
||||
// First column
|
||||
{
|
||||
var columnControls = controls.Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
|
||||
{
|
||||
null,
|
||||
null,
|
||||
null
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
84,
|
||||
84,
|
||||
96
|
||||
}));
|
||||
}
|
||||
|
||||
// Second column
|
||||
{
|
||||
var columnControls = controls.Skip(3).Take(3).ToList();
|
||||
|
||||
var columnControlsSharedSizeGroupNames = columnControls.Select(RibbonGroupBoxWrapPanel.GetSharedSizeGroupName);
|
||||
|
||||
Assert.That(columnControlsSharedSizeGroupNames, Is.EquivalentTo(new string[]
|
||||
{
|
||||
null,
|
||||
null,
|
||||
null
|
||||
}));
|
||||
|
||||
var columnControlsHeaderWidths = columnControls.Select(x => (int)GetHeaderTextBlock(x).ActualWidth);
|
||||
|
||||
Assert.That(columnControlsHeaderWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
101,
|
||||
160,
|
||||
84
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class RibbonTabsContainerTests
|
||||
{
|
||||
//private static readonly Size zeroSize = default;
|
||||
private const double ReferenceWidth = 300;
|
||||
|
||||
private static readonly double ReferenceHeight = 26;
|
||||
|
||||
[Test]
|
||||
public void Empty()
|
||||
{
|
||||
var container = new RibbonTabsContainer();
|
||||
|
||||
using (new TestRibbonWindow(container))
|
||||
{
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void With_One_Tab()
|
||||
{
|
||||
var container = new RibbonTabsContainer();
|
||||
var tabItem = new RibbonTabItem();
|
||||
container.Children.Add(tabItem);
|
||||
|
||||
using (new TestRibbonWindow(container) { Width = ReferenceWidth })
|
||||
{
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(16, ReferenceHeight)));
|
||||
|
||||
tabItem.Header = "ABC";
|
||||
|
||||
container.UpdateLayout();
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(38, ReferenceHeight)));
|
||||
}
|
||||
|
||||
//await Task.Yield();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void With_Many_Tab()
|
||||
{
|
||||
var container = new RibbonTabsContainer();
|
||||
|
||||
var longestTab = new RibbonTabItem { Header = "Longest header text" };
|
||||
var secondLongestTab = new RibbonTabItem { Header = "Header text" };
|
||||
var middleTab = new RibbonTabItem { Header = "Header" };
|
||||
var smallTab = new RibbonTabItem { Header = "Text" };
|
||||
|
||||
container.Children.Add(longestTab);
|
||||
container.Children.Add(secondLongestTab);
|
||||
container.Children.Add(middleTab);
|
||||
container.Children.Add(smallTab);
|
||||
|
||||
var childrenWidths = new[]
|
||||
{
|
||||
longestTab,
|
||||
secondLongestTab,
|
||||
middleTab,
|
||||
smallTab
|
||||
}.Select(x => x.DesiredSize.Width);
|
||||
|
||||
using (var testWindow = new TestRibbonWindow(container) { Width = ReferenceWidth })
|
||||
{
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(290, ReferenceHeight)));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
121,
|
||||
78,
|
||||
54,
|
||||
37
|
||||
}));
|
||||
|
||||
container.Measure(new Size(290, ReferenceHeight));
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(290, ReferenceHeight)));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
121,
|
||||
78,
|
||||
54,
|
||||
37
|
||||
}));
|
||||
|
||||
container.Measure(new Size(289, ReferenceHeight));
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(283, ReferenceHeight)));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
114,
|
||||
78,
|
||||
54,
|
||||
37
|
||||
}));
|
||||
|
||||
container.Measure(new Size(230, ReferenceHeight));
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(229, ReferenceHeight)));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
67,
|
||||
71,
|
||||
54,
|
||||
37
|
||||
}));
|
||||
|
||||
container.Measure(new Size(150, ReferenceHeight));
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(147, ReferenceHeight)));
|
||||
Assert.That(container.ExtentWidth, Is.EqualTo(container.ViewportWidth));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
37,
|
||||
33,
|
||||
40,
|
||||
37
|
||||
}));
|
||||
|
||||
container.Measure(new Size(130, ReferenceHeight));
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(126, ReferenceHeight)));
|
||||
Assert.That(container.ExtentWidth, Is.EqualTo(container.ViewportWidth));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
30,
|
||||
33,
|
||||
33,
|
||||
30
|
||||
}));
|
||||
|
||||
container.Measure(new Size(120, ReferenceHeight));
|
||||
|
||||
Assert.That(container.DesiredSize, Is.EqualTo(new Size(120, ReferenceHeight)));
|
||||
Assert.That(container.ExtentWidth, Is.EqualTo(121));
|
||||
|
||||
Assert.That(childrenWidths, Is.EquivalentTo(new[]
|
||||
{
|
||||
30,
|
||||
30,
|
||||
30,
|
||||
30
|
||||
}));
|
||||
}
|
||||
|
||||
//await Task.Yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
213
Others/Fluent.Ribbon/Fluent.Ribbon.Tests/Controls/RibbonTests.cs
Normal file
213
Others/Fluent.Ribbon/Fluent.Ribbon.Tests/Controls/RibbonTests.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
using Fluent.Tests.Helper;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class RibbonTests
|
||||
{
|
||||
[Test]
|
||||
public void DependencyProperties_and_DataContext_should_be_inherited_from_window()
|
||||
{
|
||||
var ribbon = new Ribbon
|
||||
{
|
||||
Menu = new Backstage(),
|
||||
StartScreen = new StartScreen()
|
||||
};
|
||||
|
||||
var enUs = XmlLanguage.GetLanguage("en-US");
|
||||
var deDe = XmlLanguage.GetLanguage("de-DE");
|
||||
|
||||
using (var window = new TestRibbonWindow(ribbon)
|
||||
{
|
||||
Language = deDe,
|
||||
DataContext = deDe
|
||||
})
|
||||
{
|
||||
ribbon.ApplyTemplate();
|
||||
|
||||
var elemens = new Dictionary<FrameworkElement, string>
|
||||
{
|
||||
{ ribbon, "Ribbon" },
|
||||
{ ribbon.Menu, "Menu" },
|
||||
{ ribbon.StartScreen, "StartScreen" },
|
||||
{ ribbon.QuickAccessToolBar, "QuickAccessToolBar" },
|
||||
{ ribbon.TabControl, "TabControl" },
|
||||
{ (FrameworkElement)ribbon.Template.FindName("PART_LayoutRoot", ribbon), "PART_LayoutRoot" },
|
||||
};
|
||||
|
||||
{
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
|
||||
}
|
||||
|
||||
{
|
||||
window.Language = enUs;
|
||||
window.DataContext = window.Language;
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
|
||||
}
|
||||
|
||||
{
|
||||
window.Language = deDe;
|
||||
window.DataContext = window.Language;
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
|
||||
}
|
||||
|
||||
{
|
||||
window.Language = enUs;
|
||||
window.DataContext = window.Language;
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, window);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DependencyProperties_and_DataContext_should_be_inherited_from_ribbon()
|
||||
{
|
||||
var ribbon = new Ribbon
|
||||
{
|
||||
Menu = new Backstage(),
|
||||
StartScreen = new StartScreen()
|
||||
};
|
||||
|
||||
var enUs = XmlLanguage.GetLanguage("en-US");
|
||||
var deDe = XmlLanguage.GetLanguage("de-DE");
|
||||
|
||||
using (var window = new TestRibbonWindow(ribbon)
|
||||
{
|
||||
Language = deDe,
|
||||
DataContext = deDe
|
||||
})
|
||||
{
|
||||
ribbon.ApplyTemplate();
|
||||
|
||||
var elemens = new Dictionary<FrameworkElement, string>
|
||||
{
|
||||
{ ribbon, "Ribbon" },
|
||||
{ ribbon.Menu, "Menu" },
|
||||
{ ribbon.StartScreen, "StartScreen" },
|
||||
{ ribbon.QuickAccessToolBar, "QuickAccessToolBar" },
|
||||
{ ribbon.TabControl, "TabControl" },
|
||||
{ (FrameworkElement)ribbon.Template.FindName("PART_LayoutRoot", ribbon), "PART_LayoutRoot" },
|
||||
};
|
||||
|
||||
{
|
||||
Assert.That(ribbon.Language, Is.EqualTo(window.Language), "Language on Window should match.");
|
||||
Assert.That(ribbon.DataContext, Is.EqualTo(window.DataContext), "DataContext on Window should match.");
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
|
||||
}
|
||||
|
||||
{
|
||||
ribbon.Language = enUs;
|
||||
ribbon.DataContext = ribbon.Language;
|
||||
|
||||
Assert.That(ribbon.Language, Is.Not.EqualTo(window.Language), "Language on Ribbon should not match Window.");
|
||||
Assert.That(ribbon.DataContext, Is.Not.EqualTo(window.DataContext), "DataContext on Ribbon should not match Window.");
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
|
||||
}
|
||||
|
||||
{
|
||||
ribbon.Language = deDe;
|
||||
ribbon.DataContext = ribbon.Language;
|
||||
|
||||
Assert.That(ribbon.Language, Is.EqualTo(window.Language), "Language on Ribbon should match Window.");
|
||||
Assert.That(ribbon.DataContext, Is.EqualTo(window.DataContext), "DataContext on Ribbon should match Window.");
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
|
||||
}
|
||||
|
||||
{
|
||||
ribbon.Language = enUs;
|
||||
ribbon.DataContext = ribbon.Language;
|
||||
|
||||
Assert.That(ribbon.Language, Is.Not.EqualTo(window.Language), "Language on Ribbon should not match Window.");
|
||||
Assert.That(ribbon.DataContext, Is.Not.EqualTo(window.DataContext), "DataContext on Ribbon should not match Window.");
|
||||
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.DataContextProperty, ribbon);
|
||||
CheckIfAllElementsHaveSameValue(elemens, FrameworkElement.LanguageProperty, ribbon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckIfAllElementsHaveSameValue(Dictionary<FrameworkElement, string> elements, DependencyProperty property, FrameworkElement expectedValueSource)
|
||||
{
|
||||
var expectedValue = expectedValueSource.GetValue(property);
|
||||
|
||||
foreach (var element in elements)
|
||||
{
|
||||
Assert.That(element.Key.GetValue(property), Is.EqualTo(expectedValue), $"{property.Name} on {element.Value} should match.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TitleBar_properties_synchronised_with_ribbon()
|
||||
{
|
||||
var ribbon = new Ribbon { ContextualGroups = { new RibbonContextualTabGroup() } };
|
||||
using (new TestRibbonWindow(ribbon))
|
||||
{
|
||||
ribbon.ApplyTemplate();
|
||||
Assert.IsNotNull(ribbon.QuickAccessToolBar);
|
||||
|
||||
var oldTitleBar = ribbon.TitleBar = new RibbonTitleBar();
|
||||
Assert.AreEqual(1, oldTitleBar.Items.Count);
|
||||
Assert.AreSame(ribbon.QuickAccessToolBar, oldTitleBar.QuickAccessToolBar);
|
||||
|
||||
var newTitleBar = new RibbonTitleBar();
|
||||
Assert.AreEqual(0, newTitleBar.Items.Count);
|
||||
Assert.IsNull(newTitleBar.QuickAccessToolBar);
|
||||
|
||||
// assign a new title bar, the contextual groups and quick access are transferred across
|
||||
ribbon.TitleBar = newTitleBar;
|
||||
Assert.AreEqual(0, oldTitleBar.Items.Count);
|
||||
Assert.IsNull(oldTitleBar.QuickAccessToolBar);
|
||||
Assert.AreEqual(1, newTitleBar.Items.Count);
|
||||
Assert.AreSame(ribbon.QuickAccessToolBar, newTitleBar.QuickAccessToolBar);
|
||||
|
||||
// remove the title bar
|
||||
ribbon.TitleBar = null;
|
||||
Assert.AreEqual(0, oldTitleBar.Items.Count);
|
||||
Assert.IsNull(oldTitleBar.QuickAccessToolBar);
|
||||
Assert.AreEqual(0, newTitleBar.Items.Count);
|
||||
Assert.IsNull(newTitleBar.QuickAccessToolBar);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_KeyTipKeys()
|
||||
{
|
||||
var ribbon = new Ribbon();
|
||||
var keyTipService = ribbon.GetFieldValue<KeyTipService>("keyTipService");
|
||||
|
||||
Assert.That(ribbon.KeyTipKeys, Is.Empty);
|
||||
Assert.That(keyTipService.KeyTipKeys, Is.EquivalentTo(KeyTipService.DefaultKeyTipKeys));
|
||||
|
||||
ribbon.KeyTipKeys.Add(Key.A);
|
||||
|
||||
Assert.That(ribbon.KeyTipKeys, Is.EquivalentTo(new[]
|
||||
{
|
||||
Key.A
|
||||
}));
|
||||
|
||||
Assert.That(keyTipService.KeyTipKeys, Is.EquivalentTo(new[]
|
||||
{
|
||||
Key.A
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Fluent.Tests.Helper;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class RibbonTitleBarTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MeasureTests
|
||||
{
|
||||
private static readonly Size zeroSize = default;
|
||||
private const double ReferenceWidth = 1024;
|
||||
private static readonly double ReferenceHeight = SystemParameters.WindowCaptionHeight;
|
||||
private static readonly Size referenceSize = new Size(ReferenceWidth, SystemParameters.WindowCaptionHeight);
|
||||
private const string QuickaccessToolbarRect = "quickAccessToolbarRect";
|
||||
private const string HeaderRect = "headerRect";
|
||||
private const string ItemsRect = "itemsRect";
|
||||
private static readonly double DefaultTitleBarHeight = SystemParameters.WindowCaptionHeight;
|
||||
|
||||
[Test]
|
||||
public void Without_Parts()
|
||||
{
|
||||
var titlebar = new RibbonTitleBar();
|
||||
|
||||
titlebar.Measure(referenceSize);
|
||||
|
||||
Assert.That(titlebar.DesiredSize, Is.EqualTo(zeroSize));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Empty()
|
||||
{
|
||||
var titlebar = new RibbonTitleBar();
|
||||
|
||||
using (new TestRibbonWindow(titlebar))
|
||||
{
|
||||
titlebar.Measure(referenceSize);
|
||||
|
||||
Assert.That(titlebar.DesiredSize, Is.EqualTo(new Size(2, DefaultTitleBarHeight)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Collapsed()
|
||||
{
|
||||
var titlebar = new RibbonTitleBar
|
||||
{
|
||||
IsCollapsed = true
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(titlebar))
|
||||
{
|
||||
titlebar.Measure(referenceSize);
|
||||
|
||||
Assert.That(titlebar.DesiredSize, Is.EqualTo(new Size(2, DefaultTitleBarHeight)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(With_Header_TestData))]
|
||||
public void With_Header(RibbonTitleBarSizeData testdata)
|
||||
{
|
||||
var titlebar = CreateNewTitlebar();
|
||||
|
||||
using (new TestRibbonWindow(titlebar))
|
||||
{
|
||||
titlebar.Measure(new Size(testdata.ConstraintWidth, ReferenceHeight));
|
||||
|
||||
var resultData = new RibbonTitleBarSizeData(testdata.ConstraintWidth, titlebar);
|
||||
Assert.That(resultData, Is.EqualTo(testdata));
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<RibbonTitleBarSizeData> With_Header_TestData()
|
||||
{
|
||||
yield return new RibbonTitleBarSizeData(ReferenceWidth, new Size(89, DefaultTitleBarHeight), zeroSize, new Size(89, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(100, new Size(89, DefaultTitleBarHeight), zeroSize, new Size(89, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(52, new Size(52, DefaultTitleBarHeight), zeroSize, new Size(54, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(50, new Size(50, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(10, new Size(10, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(With_Parts_And_Wide_Header_TestData))]
|
||||
public void With_Wide_Header(RibbonTitleBarSizeData testdata)
|
||||
{
|
||||
var titlebar = CreateNewTitlebar();
|
||||
titlebar.Header = "This is a really wide header which needs some more space";
|
||||
|
||||
using (new TestRibbonWindow(titlebar))
|
||||
{
|
||||
titlebar.Measure(new Size(testdata.ConstraintWidth, ReferenceHeight));
|
||||
|
||||
var resultData = new RibbonTitleBarSizeData(testdata.ConstraintWidth, titlebar);
|
||||
Assert.That(resultData, Is.EqualTo(testdata));
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<RibbonTitleBarSizeData> With_Parts_And_Wide_Header_TestData()
|
||||
{
|
||||
yield return new RibbonTitleBarSizeData(ReferenceWidth, new Size(309, DefaultTitleBarHeight), zeroSize, new Size(309, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(100, new Size(100, DefaultTitleBarHeight), zeroSize, new Size(102, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(52, new Size(52, DefaultTitleBarHeight), zeroSize, new Size(54, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(50, new Size(50, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(10, new Size(10, DefaultTitleBarHeight), zeroSize, new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(With_Header_And_QuickAccessItems_TestData))]
|
||||
public void With_Header_And_QuickAccessItems(RibbonTitleBarSizeData testdata)
|
||||
{
|
||||
var titlebar = CreateNewTitlebar();
|
||||
var quickAccessToolBar = (QuickAccessToolBar)(titlebar.QuickAccessToolBar = new QuickAccessToolBar());
|
||||
|
||||
using (new TestRibbonWindow(titlebar))
|
||||
{
|
||||
quickAccessToolBar.Items.Add(new TextBlock { Text = "ABC" });
|
||||
quickAccessToolBar.Items.Add(new TextBlock { Text = "ABC" });
|
||||
quickAccessToolBar.Items.Add(new TextBlock { Text = "ABC" });
|
||||
|
||||
titlebar.Measure(new Size(testdata.ConstraintWidth, ReferenceHeight));
|
||||
|
||||
var resultData = new RibbonTitleBarSizeData(testdata.ConstraintWidth, titlebar);
|
||||
Assert.That(resultData, Is.EqualTo(testdata));
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<RibbonTitleBarSizeData> With_Header_And_QuickAccessItems_TestData()
|
||||
{
|
||||
yield return new RibbonTitleBarSizeData(ReferenceWidth, new Size(169, DefaultTitleBarHeight), new Size(80, DefaultTitleBarHeight - 1), new Size(89, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(100, new Size(100, DefaultTitleBarHeight), new Size(36, DefaultTitleBarHeight - 1), new Size(66, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(52, new Size(52, DefaultTitleBarHeight), new Size(2, DefaultTitleBarHeight - 1), new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(50, new Size(50, DefaultTitleBarHeight), new Size(0, DefaultTitleBarHeight - 1), new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
yield return new RibbonTitleBarSizeData(10, new Size(10, DefaultTitleBarHeight), new Size(0, DefaultTitleBarHeight - 1), new Size(52, DefaultTitleBarHeight), zeroSize);
|
||||
}
|
||||
|
||||
public struct RibbonTitleBarSizeData
|
||||
{
|
||||
public RibbonTitleBarSizeData(double constraintWidth, Size desiredSize, Size quickAccessRectSize, Size headerRectSize, Size itemsRectSize)
|
||||
{
|
||||
this.ConstraintWidth = constraintWidth;
|
||||
this.DesiredSize = desiredSize;
|
||||
this.QuickAccessRectSize = quickAccessRectSize;
|
||||
this.HeaderRectSize = headerRectSize;
|
||||
this.ItemsRectSize = itemsRectSize;
|
||||
}
|
||||
|
||||
public RibbonTitleBarSizeData(double constraintWidth, RibbonTitleBar ribbonTitleBar)
|
||||
: this(
|
||||
constraintWidth,
|
||||
ribbonTitleBar.DesiredSize,
|
||||
ribbonTitleBar.GetFieldValue<Rect>(QuickaccessToolbarRect).Size,
|
||||
ribbonTitleBar.GetFieldValue<Rect>(HeaderRect).Size,
|
||||
ribbonTitleBar.GetFieldValue<Rect>(ItemsRect).Size)
|
||||
{
|
||||
}
|
||||
|
||||
public double ConstraintWidth { get; }
|
||||
|
||||
public Size DesiredSize { get; }
|
||||
|
||||
public Size QuickAccessRectSize { get; }
|
||||
|
||||
public Size HeaderRectSize { get; }
|
||||
|
||||
public Size ItemsRectSize { get; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{this.ConstraintWidth}=>{this.DesiredSize}]#{this.QuickAccessRectSize}#{this.HeaderRectSize}#{this.ItemsRectSize}";
|
||||
}
|
||||
}
|
||||
|
||||
private static RibbonTitleBar CreateNewTitlebar()
|
||||
{
|
||||
return new RibbonTitleBar
|
||||
{
|
||||
Header = "This is just a test",
|
||||
UseLayoutRounding = true,
|
||||
SnapsToDevicePixels = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
namespace Fluent.Tests.Controls
|
||||
{
|
||||
using System.Linq;
|
||||
using Fluent.Tests.TestClasses;
|
||||
using FluentTest.Commanding;
|
||||
using NUnit.Framework;
|
||||
|
||||
[TestFixture]
|
||||
public class SplitButtonTests
|
||||
{
|
||||
[Test]
|
||||
public void Command_Should_Not_Disable_Control()
|
||||
{
|
||||
var splitButton = new SplitButton
|
||||
{
|
||||
Command = new RelayCommand(null, () => false)
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(splitButton))
|
||||
{
|
||||
splitButton.ApplyTemplate();
|
||||
|
||||
Assert.That(splitButton.IsEnabled, Is.True);
|
||||
|
||||
var partButton = splitButton.Template.FindName("PART_Button", splitButton) as ToggleButton;
|
||||
|
||||
Assert.That(partButton, Is.Not.Null);
|
||||
Assert.That(partButton.IsEnabled, Is.False);
|
||||
|
||||
splitButton.Command = new RelayCommand(null, () => true);
|
||||
|
||||
Assert.That(splitButton.IsEnabled, Is.True);
|
||||
Assert.That(partButton.IsEnabled, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Disabling_Control_Should_Disable_Popup()
|
||||
{
|
||||
var splitButton = new SplitButton
|
||||
{
|
||||
Command = new RelayCommand(null, () => false)
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(splitButton))
|
||||
{
|
||||
splitButton.ApplyTemplate();
|
||||
|
||||
Assert.That(splitButton.IsEnabled, Is.True);
|
||||
|
||||
var dummyButton = new Button();
|
||||
|
||||
splitButton.Items.Add(dummyButton);
|
||||
|
||||
Assert.That(dummyButton.IsEnabled, Is.True);
|
||||
|
||||
splitButton.IsDropDownOpen = true;
|
||||
|
||||
splitButton.IsEnabled = false;
|
||||
|
||||
Assert.That(splitButton.IsEnabled, Is.False);
|
||||
Assert.That(dummyButton.IsEnabled, Is.False);
|
||||
|
||||
splitButton.IsDropDownOpen = false;
|
||||
|
||||
Assert.That(splitButton.IsEnabled, Is.False);
|
||||
Assert.That(dummyButton.IsEnabled, Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KeyTips_Should_Have_Postfix()
|
||||
{
|
||||
{
|
||||
var splitButton = new SplitButton
|
||||
{
|
||||
KeyTip = "Z"
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(splitButton))
|
||||
{
|
||||
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
|
||||
Assert.That(keyTipInformations, Has.Count.EqualTo(2));
|
||||
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("ZA"));
|
||||
Assert.That(keyTipInformations[1].Keys, Is.EqualTo("ZB"));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var splitButton = new SplitButton
|
||||
{
|
||||
KeyTip = "Z",
|
||||
PrimaryActionKeyTipPostfix = "X",
|
||||
SecondaryActionKeyTipPostfix = "Y"
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(splitButton))
|
||||
{
|
||||
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
|
||||
Assert.That(keyTipInformations, Has.Count.EqualTo(2));
|
||||
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("ZX"));
|
||||
Assert.That(keyTipInformations[1].Keys, Is.EqualTo("ZY"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void KeyTips_Should_Work_With_Secondary_KeyTip()
|
||||
{
|
||||
{
|
||||
var splitButton = new SplitButton
|
||||
{
|
||||
SecondaryKeyTip = "Z"
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(splitButton))
|
||||
{
|
||||
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
|
||||
Assert.That(keyTipInformations, Has.Count.EqualTo(1));
|
||||
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("Z"));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var splitButton = new SplitButton
|
||||
{
|
||||
KeyTip = "X",
|
||||
SecondaryKeyTip = "Z"
|
||||
};
|
||||
|
||||
using (new TestRibbonWindow(splitButton))
|
||||
{
|
||||
var keyTipInformations = splitButton.GetKeyTipInformations(false).ToList();
|
||||
Assert.That(keyTipInformations, Has.Count.EqualTo(2));
|
||||
Assert.That(keyTipInformations[0].Keys, Is.EqualTo("X"));
|
||||
Assert.That(keyTipInformations[1].Keys, Is.EqualTo("Z"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user