Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 961c05c

Browse files
Merge pull request #449 from jogibear9988/master
Few fixes for XAML Designer in Sharp Develop
2 parents 5e39385 + 28af1f0 commit 961c05c

26 files changed

+490
-87
lines changed

samples/XamlDesigner/App.xaml.cs

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,98 @@
22
using System.Collections.Generic;
33
using System.Configuration;
44
using System.Data;
5+
using System.Diagnostics;
6+
using System.IO;
57
using System.Linq;
8+
using System.Reflection;
9+
using System.Threading;
610
using System.Windows;
7-
using ICSharpCode.XamlDesigner.Configuration;
811
using System.Windows.Threading;
9-
using System.Diagnostics;
12+
13+
using ICSharpCode.WpfDesign.Designer;
14+
using ICSharpCode.XamlDesigner.Configuration;
1015

1116
namespace ICSharpCode.XamlDesigner
1217
{
1318
public partial class App
1419
{
1520
public static string[] Args;
1621

17-
protected override void OnStartup(StartupEventArgs e)
18-
{
22+
protected override void OnStartup(StartupEventArgs e)
23+
{
24+
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AppDomain_CurrentDomain_AssemblyResolve);
25+
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_CurrentDomain_UnhandledException);
26+
DragDropExceptionHandler.UnhandledException += new ThreadExceptionEventHandler(DragDropExceptionHandler_UnhandledException);
1927
DispatcherUnhandledException += App_DispatcherUnhandledException;
2028
Args = e.Args;
21-
base.OnStartup(e);
22-
}
29+
base.OnStartup(e);
30+
}
31+
32+
private static bool internalLoad = false;
33+
private static string lastRequesting = null;
34+
35+
Assembly AppDomain_CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
36+
{
37+
if (internalLoad)
38+
return null;
39+
40+
if (args.Name.Split(new [] { ',' })[0].Trim().EndsWith(".resources"))
41+
return null;
42+
43+
internalLoad = true;
44+
45+
Assembly ass = null;
46+
try {
47+
48+
ass = Assembly.Load(args.Name);
49+
}
50+
catch (Exception) { }
51+
52+
if (ass == null && args.RequestingAssembly != null) {
53+
lastRequesting = args.RequestingAssembly.Location;
54+
var dir = Path.GetDirectoryName(args.RequestingAssembly.Location);
55+
var file = args.Name.Split(new [] { ',' })[0].Trim() + ".dll";
56+
try {
57+
ass = Assembly.LoadFrom(Path.Combine(dir, file));
58+
}
59+
catch (Exception) { }
60+
}
61+
else if (lastRequesting != null) {
62+
var dir = Path.GetDirectoryName(lastRequesting);
63+
var file = args.Name.Split(new [] { ',' })[0].Trim() + ".dll";
64+
try {
65+
ass = Assembly.LoadFrom(Path.Combine(dir, file));
66+
}
67+
catch (Exception) { }
68+
}
69+
70+
internalLoad = false;
71+
72+
return ass;
73+
}
74+
75+
void DragDropExceptionHandler_UnhandledException(object sender, ThreadExceptionEventArgs e)
76+
{
77+
Shell.ReportException(e.Exception);
78+
79+
}
80+
81+
void AppDomain_CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
82+
{
83+
Shell.ReportException(e.ExceptionObject as Exception);
84+
}
85+
2386

2487
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
2588
{
2689
Shell.ReportException(e.Exception);
2790
e.Handled = true;
2891
}
2992

30-
protected override void OnExit(ExitEventArgs e)
31-
{
32-
Settings.Default.Save();
33-
base.OnExit(e);
34-
}
93+
protected override void OnExit(ExitEventArgs e)
94+
{
95+
Settings.Default.Save();
96+
base.OnExit(e);
97+
}
3598
}
3699
}

samples/XamlDesigner/Configuration/Settings.Designer.cs

Lines changed: 27 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/XamlDesigner/Configuration/Settings.settings

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,34 @@
66
<Value Profile="(Default)">0,0,0,0</Value>
77
</Setting>
88
<Setting Name="AvalonDockLayout" Type="System.String" Scope="User">
9-
<Value Profile="(Default)">&lt;DockingManager&gt;
10-
&lt;ResizingPanel Orientation="Horizontal"&gt;
11-
&lt;ResizingPanel ResizeWidth="200" Orientation="Vertical"&gt;
12-
&lt;DockablePane ResizeHeight="441.36166666666668" Anchor="Left"&gt;
13-
&lt;DockableContent Name="content1" AutoHide="false" /&gt;
14-
&lt;/DockablePane&gt;
15-
&lt;DockablePane ResizeWidth="200" Anchor="Left"&gt;
16-
&lt;DockableContent Name="content2" AutoHide="false" /&gt;
17-
&lt;/DockablePane&gt;
9+
<Value Profile="(Default)">&lt;DockingManager version="1.3.0"&gt;
10+
&lt;ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="0,0" Orientation="Vertical"&gt;
11+
&lt;ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1920,1153.04" Orientation="Horizontal"&gt;
12+
&lt;ResizingPanel ResizeWidth="250" ResizeHeight="*" EffectiveSize="250,1153.04" Orientation="Vertical"&gt;
13+
&lt;DockablePane ResizeWidth="0.742440632565806*" ResizeHeight="0.742440632565806*" EffectiveSize="250,851.609103178282" ID="bb7a5fd3-be24-4636-8fd6-a50a09e65e69" Anchor="Left" IsAutoHidden="false"&gt;
14+
&lt;DockableContent Name="content1" FloatingWindowSize="250,400" ChildIndex="0" Width="315" Height="1153.04" Anchor="Right" State="Docked" /&gt;
15+
&lt;/DockablePane&gt;
16+
&lt;DockablePane ResizeWidth="0.257559367434194*" ResizeHeight="0.257559367434194*" EffectiveSize="250,295.430896821718" ID="17cd1941-1004-4ed9-8cda-03c254681289" Anchor="Left" IsAutoHidden="false"&gt;
17+
&lt;DockableContent Name="content2" FloatingWindowSize="250,400" ChildIndex="0" Width="328" Height="1153.04" Anchor="Right" State="Docked" /&gt;
18+
&lt;/DockablePane&gt;
19+
&lt;/ResizingPanel&gt;
20+
&lt;ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1408,1153.04" Orientation="Vertical"&gt;
21+
&lt;DocumentPaneResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1408,965.04" Orientation="Vertical"&gt;
22+
&lt;DocumentPane IsMain="true" ResizeWidth="*" ResizeHeight="*" EffectiveSize="1408,965.04" /&gt;
23+
&lt;/DocumentPaneResizingPanel&gt;
24+
&lt;DockablePane ResizeWidth="*" ResizeHeight="182" EffectiveSize="1408,182" ID="ebd34b7e-6a89-42c6-b172-0e666b0d8a0a" Anchor="Bottom" IsAutoHidden="false"&gt;
25+
&lt;DockableContent Name="content3" FloatingWindowSize="250,400" ChildIndex="0" Width="1920" Height="400" Anchor="Bottom" State="Docked" /&gt;
26+
&lt;/DockablePane&gt;
27+
&lt;/ResizingPanel&gt;
28+
&lt;ResizingPanel ResizeWidth="250" ResizeHeight="*" EffectiveSize="250,1153.04" Orientation="Vertical"&gt;
29+
&lt;DockablePane ResizeWidth="0.145251345356991*" ResizeHeight="0.145251345356991*" EffectiveSize="250,166.609103178283" ID="aa545474-48b3-49a6-b76c-b0c625e79e4c" Anchor="Right" IsAutoHidden="false"&gt;
30+
&lt;DockableContent Name="content5" FloatingWindowSize="250,400" ChildIndex="0" Width="550.666666666667" Height="1153.04" Anchor="Right" State="Docked" /&gt;
31+
&lt;/DockablePane&gt;
32+
&lt;DockablePane ResizeWidth="0.854748654643009*" ResizeHeight="0.854748654643009*" EffectiveSize="250,980.430896821717" ID="64e5518b-2c83-4e22-908d-a510a6995c27" Anchor="Right" IsAutoHidden="false"&gt;
33+
&lt;DockableContent Name="content4" FloatingWindowSize="250,400" ChildIndex="0" Width="399.967430639324" Height="1153.04" Anchor="Right" State="Docked" /&gt;
34+
&lt;/DockablePane&gt;
35+
&lt;/ResizingPanel&gt;
1836
&lt;/ResizingPanel&gt;
19-
&lt;ResizingPanel Orientation="Vertical"&gt;
20-
&lt;DocumentPanePlaceHolder /&gt;
21-
&lt;DockablePane ResizeHeight="138" Anchor="Bottom"&gt;
22-
&lt;DockableContent Name="content3" AutoHide="false" /&gt;
23-
&lt;/DockablePane&gt;
24-
&lt;/ResizingPanel&gt;
25-
&lt;DockablePane ResizeWidth="271" Anchor="Right"&gt;
26-
&lt;DockableContent Name="content4" AutoHide="false" /&gt;
27-
&lt;/DockablePane&gt;
2837
&lt;/ResizingPanel&gt;
2938
&lt;Hidden /&gt;
3039
&lt;Windows /&gt;

samples/XamlDesigner/MainWindow.xaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<CommandBinding Command="Default:MainWindow.ExitCommand"
4343
Executed="ExitCommand_Executed" />
4444

45+
<CommandBinding Command="Default:MainWindow.RunCommand"
46+
Executed="RunCommand_Executed" />
47+
48+
<CommandBinding Command="Default:MainWindow.RenderToBitmapCommand"
49+
Executed="RenderToBitmapCommand_Executed" />
50+
4551
</Window.CommandBindings>
4652

4753
<DockPanel>
@@ -78,8 +84,12 @@
7884
<MenuItem Command="Default:MainWindow.RefreshCommand" />
7985
<MenuItem Command="Find" />
8086
</MenuItem>
87+
<MenuItem Header="Test">
88+
<MenuItem Command="Default:MainWindow.RunCommand" />
89+
<MenuItem Command="Default:MainWindow.RenderToBitmapCommand" />
90+
</MenuItem>
8191
</Menu>
82-
92+
8393
<AvalonDock:DockingManager x:Name="uxDockingManager">
8494
<AvalonDock:ResizingPanel>
8595

samples/XamlDesigner/MainWindow_Commands.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Text;
5-
using System.Windows.Input;
66
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Documents;
9+
using System.Windows.Input;
10+
using System.Windows.Markup;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Xml;
14+
15+
using Microsoft.Win32;
716

817
namespace ICSharpCode.XamlDesigner
918
{
@@ -13,6 +22,8 @@ public partial class MainWindow
1322
public static SimpleCommand SaveAllCommand = new SimpleCommand("Save All", ModifierKeys.Control | ModifierKeys.Shift, Key.S);
1423
public static SimpleCommand ExitCommand = new SimpleCommand("Exit");
1524
public static SimpleCommand RefreshCommand = new SimpleCommand("Refresh", Key.F5);
25+
public static SimpleCommand RunCommand = new SimpleCommand("Run", ModifierKeys.Shift, Key.F5);
26+
public static SimpleCommand RenderToBitmapCommand = new SimpleCommand("Render to Bitmap");
1627

1728
static void RenameCommands()
1829
{
@@ -59,6 +70,72 @@ void SaveAllCommand_Executed(object sender, ExecutedRoutedEventArgs e)
5970
{
6071
Shell.Instance.SaveAll();
6172
}
73+
74+
void RunCommand_Executed(object sender, ExecutedRoutedEventArgs e)
75+
{
76+
StringBuilder sb = new StringBuilder();
77+
var xmlWriter = XmlWriter.Create(new StringWriter(sb));
78+
Shell.Instance.CurrentDocument.DesignSurface.SaveDesigner(xmlWriter);
79+
80+
var txt = sb.ToString();
81+
var xmlReader = XmlReader.Create(new StringReader(txt));
82+
83+
var ctl = XamlReader.Load(xmlReader);
84+
85+
Window wnd = ctl as Window;
86+
if (wnd == null) {
87+
wnd = new Window();
88+
wnd.Content = ctl;
89+
}
90+
wnd.Show();
91+
}
92+
93+
void RenderToBitmapCommand_Executed(object sender, ExecutedRoutedEventArgs e)
94+
{
95+
int desiredWidth = 300;
96+
int desiredHeight = 300;
97+
98+
StringBuilder sb = new StringBuilder();
99+
var xmlWriter = XmlWriter.Create(new StringWriter(sb));
100+
Shell.Instance.CurrentDocument.DesignSurface.SaveDesigner(xmlWriter);
101+
102+
var txt = sb.ToString();
103+
var xmlReader = XmlReader.Create(new StringReader(txt));
104+
105+
var ctl = XamlReader.Load(xmlReader) as Control;
106+
if (ctl is Window) {
107+
var wnd = ctl as Window;
108+
wnd.Width = desiredWidth;
109+
wnd.Height = desiredHeight;
110+
wnd.Top = -10000;
111+
wnd.Left = -10000;
112+
wnd.Show();
113+
} else {
114+
ctl.Measure(new Size(desiredWidth, desiredHeight));
115+
ctl.Arrange(new Rect(new Size(desiredWidth, desiredHeight)));
116+
}
117+
118+
RenderTargetBitmap bmp = new RenderTargetBitmap(300, 300, 96, 96, PixelFormats.Default);
119+
bmp.Render(ctl);
120+
121+
var encoder = new PngBitmapEncoder();
122+
123+
encoder.Frames.Add(BitmapFrame.Create(bmp));
124+
125+
var dlg = new SaveFileDialog();
126+
dlg.Filter = "*.png|*.png";
127+
if (dlg.ShowDialog() == true) {
128+
using (Stream stm = File.OpenWrite(dlg.FileName)) {
129+
encoder.Save(stm);
130+
stm.Flush();
131+
}
132+
}
133+
134+
if (ctl is Window) {
135+
var wnd = ctl as Window;
136+
wnd.Close();
137+
}
138+
}
62139

63140
void ExitCommand_Executed(object sender, ExecutedRoutedEventArgs e)
64141
{

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public static void Register()
163163
Metadata.AddPopularProperty(typeof(Binding), "ElementName");
164164
Metadata.AddPopularProperty(typeof(Binding), "Converter");
165165
Metadata.AddPopularProperty(typeof(Binding), "XPath");
166+
167+
Metadata.AddPopularProperty(typeof(ItemsControl), "Items");
166168

167169
Metadata.AddValueRange(Block.LineHeightProperty, double.Epsilon, double.MaxValue);
168170
Metadata.AddValueRange(Canvas.BottomProperty, double.MinValue, double.MaxValue);
@@ -219,7 +221,7 @@ public static void Register()
219221

220222
Metadata.HideProperty(typeof(UIElement), "RenderSize");
221223
Metadata.HideProperty(FrameworkElement.NameProperty);
222-
Metadata.HideProperty(typeof(FrameworkElement), "Resources");
224+
//Metadata.HideProperty(typeof(FrameworkElement), "Resources");
223225
Metadata.HideProperty(typeof(Window), "Owner");
224226

225227
//Metadata.DisablePlacement(typeof(Button));

0 commit comments

Comments
 (0)