// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Xml;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Xaml;
using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.Designer
{
[TestFixture]
public class ModelTests : ModelTestHelper
{
[Test]
public void SetButtonWidth()
{
DesignItem button = CreateCanvasContext("");
button.Properties["Width"].SetValue(100.0);
AssertCanvasDesignerOutput(@"", button.Context);
AssertLog("");
}
[Test]
public void SetButtonWidthElementSyntax()
{
DesignItem button = CreateCanvasContext("");
button.Properties["Width"].SetValue(100.0);
AssertCanvasDesignerOutput("", button.Context);
AssertLog("");
}
[Test]
public void UndoRedoTest()
{
DesignItem button = CreateCanvasContext("");
UndoService s = button.Context.Services.GetService();
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
button.Properties["Width"].SetValue(100.0);
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
AssertLog("");
}
[Test]
public void ButtonClickEventHandler()
{
DesignItem button = CreateCanvasContext("");
Assert.AreEqual("OnClick", button.Properties["Click"].ValueOnInstance);
button.Properties["Click"].Reset();
button.Properties["KeyDown"].SetValue("ButtonKeyDown");
AssertCanvasDesignerOutput(@"", button.Context);
AssertLog("");
}
[Test]
public void ButtonClickEventHandlerUndoRedo()
{
DesignItem button = CreateCanvasContext("");
UndoService s = button.Context.Services.GetService();
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
button.Properties["Click"].SetValue("OnClick");
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
button.Properties["Click"].SetValue("OnClick2");
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Undo();
Assert.IsTrue(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
AssertLog("");
}
[Test]
public void UndoRedoChangeGroupTest()
{
DesignItem button = CreateCanvasContext("");
UndoService s = button.Context.Services.GetService();
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
using (ChangeGroup g = button.OpenGroup("Resize")) {
button.Properties["Width"].SetValue(100.0);
button.Properties["Height"].SetValue(200.0);
g.Commit();
}
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(@"", button.Context);
AssertLog("");
}
[Test]
public void UndoRedoImplicitList()
{
UndoRedoListInternal(false);
}
[Test]
public void UndoRedoExplicitList()
{
UndoRedoListInternal(true);
}
void UndoRedoListInternal(bool useExplicitList)
{
DesignItem button = CreateCanvasContext("");
UndoService s = button.Context.Services.GetService();
IComponentService component = button.Context.Services.Component;
string expectedXamlWithList;
DesignItemProperty otherListProp;
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
using (ChangeGroup g = button.OpenGroup("UndoRedoListInternal test")) {
DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
otherListProp = containerItem.Properties["OtherList"];
if(useExplicitList) {
otherListProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList());
expectedXamlWithList = @"";
} else {
expectedXamlWithList = @"";
}
DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Properties["StringProp"].SetValue("String value");
otherListProp.CollectionElements.Add(exampleClassItem);
button.Properties["Tag"].SetValue(containerItem);
g.Commit();
}
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
otherListProp = button.Properties["Tag"].Value.Properties["OtherList"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput("", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
otherListProp = button.Properties["Tag"].Value.Properties["OtherList"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count);
AssertLog("");
}
[Test]
public void UndoRedoImplicitDictionary()
{
UndoRedoDictionaryInternal(false);
}
[Test]
public void UndoRedoExplicitDictionary()
{
UndoRedoDictionaryInternal(true);
}
void UndoRedoDictionaryInternal(bool useExplicitDictionary)
{
DesignItem button = CreateCanvasContext("");
UndoService s = button.Context.Services.GetService();
IComponentService component = button.Context.Services.Component;
string expectedXamlWithDictionary;
DesignItemProperty dictionaryProp;
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
using (ChangeGroup g = button.OpenGroup("UndoRedoDictionaryInternal test")) {
DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
dictionaryProp = containerItem.Properties["Dictionary"];
if(useExplicitDictionary) {
dictionaryProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary());
expectedXamlWithDictionary = @"";
} else {
expectedXamlWithDictionary = @"";
}
DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Key = "testKey";
exampleClassItem.Properties["StringProp"].SetValue("String value");
dictionaryProp.CollectionElements.Add(exampleClassItem);
button.Properties["Tag"].SetValue(containerItem);
g.Commit();
}
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput("", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvas()
{
DesignItem button = CreateCanvasContext("");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("\n", button.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasExplicitChildrenCollection()
{
DesignItem button = CreateCanvasContext("");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("\n \n \n", button.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyImplicitPanelChildrenCollection()
{
DesignItem canvas = CreateCanvasContext("");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("", canvas.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyImplicitPanelChildrenCollectionEmptyTag()
{
DesignItem canvas = CreateCanvasContext("");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("", canvas.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyExplicitPanelChildrenCollection()
{
DesignItem canvas = CreateCanvasContext("");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("", canvas.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyExplicitCanvasChildrenCollection()
{
DesignItem canvas = CreateCanvasContext("");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("", canvas.Context);
AssertLog("");
}
[Test]
public void InsertTextBoxInCanvas()
{
DesignItem button = CreateCanvasContext("5060");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
DesignItem checkBox = canvas.Services.Component.RegisterComponentForDesigner(new CheckBox());
canvas.Properties["Children"].CollectionElements.Insert(0, checkBox);
AssertCanvasDesignerOutput("50\n" +
"\n" +
"\n" +
"\n" +
"60", button.Context);
AssertLog("");
}
[Test]
public void ClearImplicitChildCollection()
{
DesignItem canvas = CreateCanvasContext("");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Clear();
AssertCanvasDesignerOutput("", canvas.Context);
AssertLog("");
}
[Test]
public void ClearExplicitList()
{
DesignItem button = CreateCanvasContext("");
button.Properties["Tag"].SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
var containerItem = button.Properties["Tag"].Value;
var otherListProp = containerItem.Properties["OtherList"];
otherListProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList());
DesignItem exampleClassItem = button.Context.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Properties["StringProp"].SetValue("String value");
otherListProp.CollectionElements.Add(exampleClassItem);
var listInstance = (ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance;
Assert.AreEqual(1, listInstance.Count);
Assert.AreEqual(1, otherListProp.CollectionElements.Count);
button.Properties["Tag"].Value.Properties["OtherList"].CollectionElements.Clear();
Assert.AreEqual(0, listInstance.Count);
Assert.AreEqual(0, otherListProp.CollectionElements.Count);
AssertCanvasDesignerOutput(@"", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
AssertLog("");
}
[Test]
public void ClearExplicitDictionary()
{
DesignItem button = CreateCanvasContext("");
button.Properties["Tag"].SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
var containerItem = button.Properties["Tag"].Value;
var dictionaryProp = containerItem.Properties["Dictionary"];
dictionaryProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary());
DesignItem exampleClassItem = button.Context.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Key = "testKey";
exampleClassItem.Properties["StringProp"].SetValue("String value");
dictionaryProp.CollectionElements.Add(exampleClassItem);
var dictionaryInstance = (ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance;
Assert.AreEqual(1, dictionaryInstance.Count);
Assert.AreEqual(1, dictionaryProp.CollectionElements.Count);
button.Properties["Tag"].Value.Properties["Dictionary"].CollectionElements.Clear();
Assert.AreEqual(0, dictionaryInstance.Count);
Assert.AreEqual(0, dictionaryProp.CollectionElements.Count);
dictionaryProp.CollectionElements.Add(exampleClassItem);
Assert.AreEqual(1, dictionaryInstance.Count);
Assert.AreEqual(1, dictionaryProp.CollectionElements.Count);
button.Properties["Tag"].Value.Properties["Dictionary"].CollectionElements.Clear();
Assert.AreEqual(0, dictionaryInstance.Count);
Assert.AreEqual(0, dictionaryProp.CollectionElements.Count);
AssertCanvasDesignerOutput(@"", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
AssertLog("");
}
[Test]
public void AddMultiBindingToTextBox()
{
DesignItem button = CreateCanvasContext("");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
textBox.Properties[TextBox.TextProperty].SetValue(new MultiBinding());
DesignItem multiBindingItem = textBox.Properties[TextBox.TextProperty].Value;
multiBindingItem.Properties["Converter"].SetValue(new MyMultiConverter());
DesignItemProperty bindingsProp = multiBindingItem.ContentProperty;
Assert.IsTrue(bindingsProp.IsCollection);
Assert.AreEqual(bindingsProp.Name, "Bindings");
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
bindingItem.Properties["Path"].SetValue("SomeProperty");
bindingsProp.CollectionElements.Add(bindingItem);
string expectedXaml = "\n" +
"\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
"";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
}
[Test]
public void AddSimpleBinding()
{
DesignItem button = CreateCanvasContext("");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
textBox.Properties[TextBox.TextProperty].SetValue(new Binding());
textBox.Properties[TextBox.TextProperty].Value.Properties["Path"].SetValue("SomeProperty");
string expectedXaml = "\n" +
"\n";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
}
[Test]
public void AddBindingWithStaticResource()
{
DesignItem button = CreateCanvasContext("");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
DesignItemProperty resProp = canvas.Properties.GetProperty("Resources");
Assert.IsTrue(resProp.IsCollection);
DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass());
exampleClassItem.Key = "bindingSource";
resProp.CollectionElements.Add(exampleClassItem);
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
textBox.Properties[TextBox.TextProperty].SetValue(bindingItem);
bindingItem.Properties["Path"].SetValue("StringProp");
bindingItem.Properties["Source"].SetValue(new StaticResourceExtension());
bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource");
string expectedXaml = "\n" +
" \n" +
"\n" +
"\n" +
"";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
}
void AddBindingWithStaticResourceWhereResourceOnSameElement(bool setBindingPropertiesAfterSet)
{
DesignItem button = CreateCanvasContext("");
DesignItem canvas = button.Parent;
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
DesignItemProperty resProp = textBox.Properties.GetProperty("Resources");
Assert.IsTrue(resProp.IsCollection);
DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass());
exampleClassItem.Key = "bindingSource";
resProp.CollectionElements.Add(exampleClassItem);
DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding());
if (!setBindingPropertiesAfterSet) {
bindingItem.Properties["Path"].SetValue("StringProp");
bindingItem.Properties["Source"].SetValue(new StaticResourceExtension());
bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource");
}
textBox.Properties[TextBox.TextProperty].SetValue(bindingItem);
if (setBindingPropertiesAfterSet) {
bindingItem.Properties["Path"].SetValue("StringProp");
bindingItem.Properties["Source"].SetValue(new StaticResourceExtension());
bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource");
}
string expectedXaml = "\n" +
"\n" +
" \n" +
" \n" +
" \n" +
" \n" +
"";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
}
[Test]
public void AddBindingWithStaticResourceWhereResourceOnSameElement()
{
AddBindingWithStaticResourceWhereResourceOnSameElement(false);
}
[Test]
public void AddBindingWithStaticResourceWhereResourceOnSameElementAlt()
{
AddBindingWithStaticResourceWhereResourceOnSameElement(true);
}
[Test]
public void AddBrushAsResource()
{
DesignItem checkBox = CreateCanvasContext("");
DesignItem canvas = checkBox.Parent;
DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources");
DesignItem brush = canvas.Services.Component.RegisterComponentForDesigner(new SolidColorBrush());
brush.Key = "testBrush";
brush.Properties[SolidColorBrush.ColorProperty].SetValue(Colors.Fuchsia);
Assert.IsTrue(canvasResources.IsCollection);
canvasResources.CollectionElements.Add(brush);
checkBox.Properties[CheckBox.ForegroundProperty].SetValue(new StaticResourceExtension());
DesignItemProperty prop = checkBox.Properties[CheckBox.ForegroundProperty];
prop.Value.Properties["ResourceKey"].SetValue("testBrush");
string expectedXaml = "\n" +
" \n" +
"\n" +
"";
AssertCanvasDesignerOutput(expectedXaml, checkBox.Context);
AssertLog("");
}
[Test]
public void AddNativeTypeAsResource(object component, string expectedXamlValue)
{
DesignItem textBlock = CreateCanvasContext("");
DesignItem canvas = textBlock.Parent;
DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources");
DesignItem componentItem = canvas.Services.Component.RegisterComponentForDesigner(component);
componentItem.Key = "res1";
Assert.IsTrue(canvasResources.IsCollection);
canvasResources.CollectionElements.Add(componentItem);
DesignItemProperty prop = textBlock.Properties[TextBlock.TagProperty];
prop.SetValue(new StaticResourceExtension());
prop.Value.Properties["ResourceKey"].SetValue("res1");
string typeName = component.GetType().Name;
string expectedXaml = "\n" +
" " + expectedXamlValue + "\n" +
"\n" +
"";
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\"");
AssertLog("");
}
[Test]
public void AddStringAsResource()
{
AddNativeTypeAsResource("stringresource 1", "stringresource 1");
}
[Test]
public void AddDoubleAsResource()
{
AddNativeTypeAsResource(0.0123456789d, "0.0123456789");
}
[Test]
public void AddInt32AsResource()
{
const int i = 123;
AddNativeTypeAsResource(i, "123");
}
}
public class MyMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return new object[targetTypes.Length];
}
}
public class ExampleClass
{
string stringProp;
public string StringProp {
get { return stringProp; }
set { stringProp = value; }
}
}
}