38 changed files with 943 additions and 205 deletions
@ -0,0 +1,11 @@ |
|||||||
|
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.EditStyleContextMenu" |
||||||
|
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" |
||||||
|
> |
||||||
|
<MenuItem Header="{Binding EditStyle, Source={x:Static Translation:Translations.Instance}}" Click="Click_EditStyle"> |
||||||
|
<MenuItem.Icon> |
||||||
|
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/edit.png" /> |
||||||
|
</MenuItem.Icon> |
||||||
|
</MenuItem> |
||||||
|
</ContextMenu> |
||||||
@ -0,0 +1,68 @@ |
|||||||
|
// 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.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Markup; |
||||||
|
using System.Xml; |
||||||
|
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor; |
||||||
|
using ICSharpCode.WpfDesign.Designer.Xaml; |
||||||
|
using ICSharpCode.WpfDesign.XamlDom; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Designer.Extensions |
||||||
|
{ |
||||||
|
public partial class EditStyleContextMenu |
||||||
|
{ |
||||||
|
private DesignItem designItem; |
||||||
|
|
||||||
|
public EditStyleContextMenu(DesignItem designItem) |
||||||
|
{ |
||||||
|
this.designItem = designItem; |
||||||
|
|
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
void Click_EditStyle(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
var element = designItem.View; |
||||||
|
object defaultStyleKey = element.GetValue(FrameworkElement.DefaultStyleKeyProperty); |
||||||
|
Style style = Application.Current.TryFindResource(defaultStyleKey) as Style; |
||||||
|
|
||||||
|
var service = ((XamlComponentService) designItem.Services.Component); |
||||||
|
|
||||||
|
var ms = new MemoryStream(); |
||||||
|
XmlTextWriter writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8); |
||||||
|
writer.Formatting = Formatting.Indented; |
||||||
|
XamlWriter.Save(style, writer); |
||||||
|
|
||||||
|
var rootItem = this.designItem.Context.RootItem as XamlDesignItem; |
||||||
|
|
||||||
|
ms.Position = 0; |
||||||
|
var sr = new StreamReader(ms); |
||||||
|
var xaml = sr.ReadToEnd(); |
||||||
|
|
||||||
|
var xamlObject = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext)this.designItem.Context).ParserSettings); |
||||||
|
|
||||||
|
var styleDesignItem=service.RegisterXamlComponentRecursive(xamlObject); |
||||||
|
designItem.Properties.GetProperty("Resources").CollectionElements.Add(styleDesignItem); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
// 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.Linq; |
||||||
|
using System.Windows.Controls; |
||||||
|
using ICSharpCode.WpfDesign.Adorners; |
||||||
|
using ICSharpCode.WpfDesign.Extensions; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Designer.Extensions |
||||||
|
{ |
||||||
|
[ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))] |
||||||
|
[ExtensionFor(typeof (Control))] |
||||||
|
[Extension(Order = 10)] |
||||||
|
public class EditStyleContextMenuExtension : PrimarySelectionAdornerProvider |
||||||
|
{ |
||||||
|
DesignPanel panel; |
||||||
|
ContextMenu contextMenu; |
||||||
|
|
||||||
|
protected override void OnInitialized() |
||||||
|
{ |
||||||
|
base.OnInitialized(); |
||||||
|
|
||||||
|
contextMenu = new EditStyleContextMenu(ExtendedItem); |
||||||
|
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; |
||||||
|
if (panel != null) |
||||||
|
panel.AddContextMenu(contextMenu); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnRemove() |
||||||
|
{ |
||||||
|
if (panel != null) |
||||||
|
panel.RemoveContextMenu(contextMenu); |
||||||
|
|
||||||
|
base.OnRemove(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Tests.XamlDom |
||||||
|
{ |
||||||
|
public class ExampleControl : Control |
||||||
|
{ |
||||||
|
public object Property1 |
||||||
|
{ |
||||||
|
get { return (object)GetValue(Property1Property); } |
||||||
|
set { SetValue(Property1Property, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public static readonly DependencyProperty Property1Property = |
||||||
|
DependencyProperty.Register("Property1", typeof(object), typeof(ExampleControl), new PropertyMetadata(null)); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,133 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Markup; |
||||||
|
using System.Xml; |
||||||
|
using ICSharpCode.WpfDesign.XamlDom; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.WpfDesign.Designer; |
||||||
|
using ICSharpCode.WpfDesign.Designer.UIExtensions; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Tests.XamlDom |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NamescopeTest : TestHelper |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// NamescopeTest 1
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void NamescopeTest1() |
||||||
|
{ |
||||||
|
var xaml= @"
|
||||||
|
<UserControl |
||||||
|
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
|
||||||
|
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @""" |
||||||
|
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
|
||||||
|
x:Name=""root"" |
||||||
|
> |
||||||
|
<Grid x:Name=""rootGrid"" > |
||||||
|
<Button x:Name=""aa"" /> |
||||||
|
<Button x:Name=""bb"" /> |
||||||
|
<t:ExampleControl Property1=""{x:Reference aa}"" /> |
||||||
|
</Grid> |
||||||
|
</UserControl>";
|
||||||
|
|
||||||
|
var obj = XamlParser.Parse(new StringReader(xaml)); |
||||||
|
|
||||||
|
((FrameworkElement)obj.RootInstance).CreateVisualTree(); |
||||||
|
|
||||||
|
var example = ((FrameworkElement) obj.RootInstance).TryFindChild<ExampleControl>(); |
||||||
|
var buttonAa = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa"); |
||||||
|
|
||||||
|
Assert.AreEqual(example.Property1, buttonAa); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NamescopeTest 2
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void NamescopeTest2() |
||||||
|
{ |
||||||
|
var xaml = @"
|
||||||
|
<UserControl |
||||||
|
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
|
||||||
|
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @""" |
||||||
|
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
|
||||||
|
x:Name=""root"" |
||||||
|
> |
||||||
|
<Grid x:Name=""grid"" > |
||||||
|
<Button Content=""level0"" x:Name=""aa"" /> |
||||||
|
<t:NamscopeTestUsercontrol /> |
||||||
|
<Button Content=""level0"" x:Name=""bb"" /> |
||||||
|
<t:ExampleControl Property1=""{x:Reference aa}"" /> |
||||||
|
<t:ExampleControl x:Name=""exampleb"" Property1=""{x:Reference bb}"" /> |
||||||
|
</Grid> |
||||||
|
</UserControl>";
|
||||||
|
|
||||||
|
object officialResult = XamlReader.Load(new XmlTextReader(new StringReader(xaml))); |
||||||
|
((FrameworkElement)officialResult).CreateVisualTree(); |
||||||
|
var example1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>(); |
||||||
|
var exampleb1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>("exampleb"); |
||||||
|
var buttonAa1 = ((FrameworkElement)officialResult).TryFindChild<Button>("aa"); |
||||||
|
var buttonbb1 = ((FrameworkElement)officialResult).TryFindChild<Button>("bb"); |
||||||
|
Assert.AreEqual(example1.Property1, buttonAa1); |
||||||
|
Assert.AreNotEqual(exampleb1.Property1, buttonbb1); |
||||||
|
|
||||||
|
|
||||||
|
var obj = XamlParser.Parse(new StringReader(xaml)); |
||||||
|
((FrameworkElement)obj.RootInstance).CreateVisualTree(); |
||||||
|
var example2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>(); |
||||||
|
var exampleb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>("exampleb"); |
||||||
|
var buttonAa2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa"); |
||||||
|
var buttonbb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("bb"); |
||||||
|
Assert.AreEqual(example2.Property1, buttonAa2); |
||||||
|
Assert.AreNotEqual(exampleb2.Property1, buttonbb2); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NamescopeTest 3
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void NamescopeTest3() |
||||||
|
{ |
||||||
|
var xaml = @"
|
||||||
|
<Grid |
||||||
|
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
|
||||||
|
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @""" |
||||||
|
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
|
||||||
|
x:Name=""root"" |
||||||
|
> |
||||||
|
<Button Content=""level0"" x:Name=""aa"" /> |
||||||
|
<t:NamscopeTestUsercontrol /> |
||||||
|
<Button Content=""level0"" x:Name=""bb"" /> |
||||||
|
<t:ExampleControl Property1=""{x:Reference aa}"" /> |
||||||
|
<t:ExampleControl x:Name=""exampleb"" Property1=""{x:Reference bb}"" /> |
||||||
|
</Grid>";
|
||||||
|
|
||||||
|
object officialResult = XamlReader.Load(new XmlTextReader(new StringReader(xaml))); |
||||||
|
((FrameworkElement)officialResult).CreateVisualTree(); |
||||||
|
var example1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>(); |
||||||
|
var exampleb1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>("exampleb"); |
||||||
|
var buttonAa1 = ((FrameworkElement)officialResult).TryFindChild<Button>("aa"); |
||||||
|
var buttonbb1 = ((FrameworkElement)officialResult).TryFindChild<Button>("bb"); |
||||||
|
Assert.AreEqual(example1.Property1, buttonAa1); |
||||||
|
Assert.AreNotEqual(exampleb1.Property1, buttonbb1); |
||||||
|
|
||||||
|
|
||||||
|
var obj = XamlParser.Parse(new StringReader(xaml)); |
||||||
|
((FrameworkElement)obj.RootInstance).CreateVisualTree(); |
||||||
|
var example2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>(); |
||||||
|
var exampleb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>("exampleb"); |
||||||
|
var buttonAa2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa"); |
||||||
|
var buttonbb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("bb"); |
||||||
|
Assert.AreEqual(example2.Property1, buttonAa2); |
||||||
|
Assert.AreNotEqual(exampleb2.Property1, buttonbb2); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<UserControl x:Class="ICSharpCode.WpfDesign.Tests.XamlDom.NamscopeTestUsercontrol" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||||
|
xmlns:local="clr-namespace:ICSharpCode.WpfDesign.Tests.XamlDom" |
||||||
|
mc:Ignorable="d" x:Name="usercontrol" |
||||||
|
d:DesignHeight="300" d:DesignWidth="300"> |
||||||
|
<Grid x:Name="grid"> |
||||||
|
<Button x:Name="aa" Content="level1" /> |
||||||
|
<Button x:Name="bb" Content="level1" /> |
||||||
|
</Grid> |
||||||
|
</UserControl> |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Data; |
||||||
|
using System.Windows.Documents; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
using System.Windows.Media.Imaging; |
||||||
|
using System.Windows.Navigation; |
||||||
|
using System.Windows.Shapes; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Tests.XamlDom |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for NamscopeTestUsercontrol.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class NamscopeTestUsercontrol : UserControl |
||||||
|
{ |
||||||
|
public NamscopeTestUsercontrol() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
// 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.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Reflection; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Markup; |
||||||
|
using System.Xml; |
||||||
|
using System.Xml.XPath; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.XamlDom |
||||||
|
{ |
||||||
|
public static class TemplateHelper |
||||||
|
{ |
||||||
|
public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement) |
||||||
|
{ |
||||||
|
var nav = xmlElement.CreateNavigator(); |
||||||
|
|
||||||
|
var ns = new Dictionary<string, string>(); |
||||||
|
while (true) |
||||||
|
{ |
||||||
|
var nsInScope = nav.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); |
||||||
|
foreach (var ak in nsInScope) |
||||||
|
{ |
||||||
|
if (!ns.ContainsKey(ak.Key) && ak.Key != "") |
||||||
|
ns.Add(ak.Key, ak.Value); |
||||||
|
} |
||||||
|
if (!nav.MoveToParent()) |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
foreach (var dictentry in ns) |
||||||
|
{ |
||||||
|
xmlElement.SetAttribute("xmlns:" + dictentry.Key, dictentry.Value); |
||||||
|
} |
||||||
|
|
||||||
|
var xaml = xmlElement.OuterXml; |
||||||
|
StringReader stringReader = new StringReader(xaml); |
||||||
|
XmlReader xmlReader = XmlReader.Create(stringReader); |
||||||
|
return (FrameworkTemplate)XamlReader.Load(xmlReader); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue