diff --git a/samples/XamlDesigner/App.xaml.cs b/samples/XamlDesigner/App.xaml.cs index 5ec88cffc2..6a9be5c98c 100644 --- a/samples/XamlDesigner/App.xaml.cs +++ b/samples/XamlDesigner/App.xaml.cs @@ -2,11 +2,16 @@ using System; using System.Collections.Generic; using System.Configuration; using System.Data; +using System.Diagnostics; +using System.IO; using System.Linq; +using System.Reflection; +using System.Threading; using System.Windows; -using ICSharpCode.XamlDesigner.Configuration; using System.Windows.Threading; -using System.Diagnostics; + +using ICSharpCode.WpfDesign.Designer; +using ICSharpCode.XamlDesigner.Configuration; namespace ICSharpCode.XamlDesigner { @@ -14,12 +19,70 @@ namespace ICSharpCode.XamlDesigner { public static string[] Args; - protected override void OnStartup(StartupEventArgs e) - { + protected override void OnStartup(StartupEventArgs e) + { + AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AppDomain_CurrentDomain_AssemblyResolve); + AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_CurrentDomain_UnhandledException); + DragDropExceptionHandler.UnhandledException += new ThreadExceptionEventHandler(DragDropExceptionHandler_UnhandledException); DispatcherUnhandledException += App_DispatcherUnhandledException; Args = e.Args; - base.OnStartup(e); - } + base.OnStartup(e); + } + + private static bool internalLoad = false; + private static string lastRequesting = null; + + Assembly AppDomain_CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + if (internalLoad) + return null; + + if (args.Name.Split(new [] { ',' })[0].Trim().EndsWith(".resources")) + return null; + + internalLoad = true; + + Assembly ass = null; + try { + + ass = Assembly.Load(args.Name); + } + catch (Exception) { } + + if (ass == null && args.RequestingAssembly != null) { + lastRequesting = args.RequestingAssembly.Location; + var dir = Path.GetDirectoryName(args.RequestingAssembly.Location); + var file = args.Name.Split(new [] { ',' })[0].Trim() + ".dll"; + try { + ass = Assembly.LoadFrom(Path.Combine(dir, file)); + } + catch (Exception) { } + } + else if (lastRequesting != null) { + var dir = Path.GetDirectoryName(lastRequesting); + var file = args.Name.Split(new [] { ',' })[0].Trim() + ".dll"; + try { + ass = Assembly.LoadFrom(Path.Combine(dir, file)); + } + catch (Exception) { } + } + + internalLoad = false; + + return ass; + } + + void DragDropExceptionHandler_UnhandledException(object sender, ThreadExceptionEventArgs e) + { + Shell.ReportException(e.Exception); + + } + + void AppDomain_CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Shell.ReportException(e.ExceptionObject as Exception); + } + void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { @@ -27,10 +90,10 @@ namespace ICSharpCode.XamlDesigner e.Handled = true; } - protected override void OnExit(ExitEventArgs e) - { - Settings.Default.Save(); - base.OnExit(e); - } + protected override void OnExit(ExitEventArgs e) + { + Settings.Default.Save(); + base.OnExit(e); + } } } diff --git a/samples/XamlDesigner/Configuration/Settings.Designer.cs b/samples/XamlDesigner/Configuration/Settings.Designer.cs index 9a835b8cf5..856ed1ff13 100644 --- a/samples/XamlDesigner/Configuration/Settings.Designer.cs +++ b/samples/XamlDesigner/Configuration/Settings.Designer.cs @@ -37,25 +37,34 @@ namespace ICSharpCode.XamlDesigner.Configuration { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute(@" - - - - - - - - + [global::System.Configuration.DefaultSettingValueAttribute(@" + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - diff --git a/samples/XamlDesigner/Configuration/Settings.settings b/samples/XamlDesigner/Configuration/Settings.settings index 65e359e302..33f62b33b9 100644 --- a/samples/XamlDesigner/Configuration/Settings.settings +++ b/samples/XamlDesigner/Configuration/Settings.settings @@ -6,25 +6,34 @@ 0,0,0,0 - <DockingManager> - <ResizingPanel Orientation="Horizontal"> - <ResizingPanel ResizeWidth="200" Orientation="Vertical"> - <DockablePane ResizeHeight="441.36166666666668" Anchor="Left"> - <DockableContent Name="content1" AutoHide="false" /> - </DockablePane> - <DockablePane ResizeWidth="200" Anchor="Left"> - <DockableContent Name="content2" AutoHide="false" /> - </DockablePane> + <DockingManager version="1.3.0"> + <ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="0,0" Orientation="Vertical"> + <ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1920,1153.04" Orientation="Horizontal"> + <ResizingPanel ResizeWidth="250" ResizeHeight="*" EffectiveSize="250,1153.04" Orientation="Vertical"> + <DockablePane ResizeWidth="0.742440632565806*" ResizeHeight="0.742440632565806*" EffectiveSize="250,851.609103178282" ID="bb7a5fd3-be24-4636-8fd6-a50a09e65e69" Anchor="Left" IsAutoHidden="false"> + <DockableContent Name="content1" FloatingWindowSize="250,400" ChildIndex="0" Width="315" Height="1153.04" Anchor="Right" State="Docked" /> + </DockablePane> + <DockablePane ResizeWidth="0.257559367434194*" ResizeHeight="0.257559367434194*" EffectiveSize="250,295.430896821718" ID="17cd1941-1004-4ed9-8cda-03c254681289" Anchor="Left" IsAutoHidden="false"> + <DockableContent Name="content2" FloatingWindowSize="250,400" ChildIndex="0" Width="328" Height="1153.04" Anchor="Right" State="Docked" /> + </DockablePane> + </ResizingPanel> + <ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1408,1153.04" Orientation="Vertical"> + <DocumentPaneResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1408,965.04" Orientation="Vertical"> + <DocumentPane IsMain="true" ResizeWidth="*" ResizeHeight="*" EffectiveSize="1408,965.04" /> + </DocumentPaneResizingPanel> + <DockablePane ResizeWidth="*" ResizeHeight="182" EffectiveSize="1408,182" ID="ebd34b7e-6a89-42c6-b172-0e666b0d8a0a" Anchor="Bottom" IsAutoHidden="false"> + <DockableContent Name="content3" FloatingWindowSize="250,400" ChildIndex="0" Width="1920" Height="400" Anchor="Bottom" State="Docked" /> + </DockablePane> + </ResizingPanel> + <ResizingPanel ResizeWidth="250" ResizeHeight="*" EffectiveSize="250,1153.04" Orientation="Vertical"> + <DockablePane ResizeWidth="0.145251345356991*" ResizeHeight="0.145251345356991*" EffectiveSize="250,166.609103178283" ID="aa545474-48b3-49a6-b76c-b0c625e79e4c" Anchor="Right" IsAutoHidden="false"> + <DockableContent Name="content5" FloatingWindowSize="250,400" ChildIndex="0" Width="550.666666666667" Height="1153.04" Anchor="Right" State="Docked" /> + </DockablePane> + <DockablePane ResizeWidth="0.854748654643009*" ResizeHeight="0.854748654643009*" EffectiveSize="250,980.430896821717" ID="64e5518b-2c83-4e22-908d-a510a6995c27" Anchor="Right" IsAutoHidden="false"> + <DockableContent Name="content4" FloatingWindowSize="250,400" ChildIndex="0" Width="399.967430639324" Height="1153.04" Anchor="Right" State="Docked" /> + </DockablePane> + </ResizingPanel> </ResizingPanel> - <ResizingPanel Orientation="Vertical"> - <DocumentPanePlaceHolder /> - <DockablePane ResizeHeight="138" Anchor="Bottom"> - <DockableContent Name="content3" AutoHide="false" /> - </DockablePane> - </ResizingPanel> - <DockablePane ResizeWidth="271" Anchor="Right"> - <DockableContent Name="content4" AutoHide="false" /> - </DockablePane> </ResizingPanel> <Hidden /> <Windows /> diff --git a/samples/XamlDesigner/MainWindow.xaml b/samples/XamlDesigner/MainWindow.xaml index b3cd9e3b43..881a18b050 100644 --- a/samples/XamlDesigner/MainWindow.xaml +++ b/samples/XamlDesigner/MainWindow.xaml @@ -42,6 +42,12 @@ + + + + @@ -78,8 +84,12 @@ + + + + - + diff --git a/samples/XamlDesigner/MainWindow_Commands.cs b/samples/XamlDesigner/MainWindow_Commands.cs index 040f15a27c..bb6c0c7b5b 100644 --- a/samples/XamlDesigner/MainWindow_Commands.cs +++ b/samples/XamlDesigner/MainWindow_Commands.cs @@ -1,9 +1,18 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; -using System.Windows.Input; using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Xml; + +using Microsoft.Win32; namespace ICSharpCode.XamlDesigner { @@ -13,6 +22,8 @@ namespace ICSharpCode.XamlDesigner public static SimpleCommand SaveAllCommand = new SimpleCommand("Save All", ModifierKeys.Control | ModifierKeys.Shift, Key.S); public static SimpleCommand ExitCommand = new SimpleCommand("Exit"); public static SimpleCommand RefreshCommand = new SimpleCommand("Refresh", Key.F5); + public static SimpleCommand RunCommand = new SimpleCommand("Run", ModifierKeys.Shift, Key.F5); + public static SimpleCommand RenderToBitmapCommand = new SimpleCommand("Render to Bitmap"); static void RenameCommands() { @@ -59,6 +70,72 @@ namespace ICSharpCode.XamlDesigner { Shell.Instance.SaveAll(); } + + void RunCommand_Executed(object sender, ExecutedRoutedEventArgs e) + { + StringBuilder sb = new StringBuilder(); + var xmlWriter = XmlWriter.Create(new StringWriter(sb)); + Shell.Instance.CurrentDocument.DesignSurface.SaveDesigner(xmlWriter); + + var txt = sb.ToString(); + var xmlReader = XmlReader.Create(new StringReader(txt)); + + var ctl = XamlReader.Load(xmlReader); + + Window wnd = ctl as Window; + if (wnd == null) { + wnd = new Window(); + wnd.Content = ctl; + } + wnd.Show(); + } + + void RenderToBitmapCommand_Executed(object sender, ExecutedRoutedEventArgs e) + { + int desiredWidth = 300; + int desiredHeight = 300; + + StringBuilder sb = new StringBuilder(); + var xmlWriter = XmlWriter.Create(new StringWriter(sb)); + Shell.Instance.CurrentDocument.DesignSurface.SaveDesigner(xmlWriter); + + var txt = sb.ToString(); + var xmlReader = XmlReader.Create(new StringReader(txt)); + + var ctl = XamlReader.Load(xmlReader) as Control; + if (ctl is Window) { + var wnd = ctl as Window; + wnd.Width = desiredWidth; + wnd.Height = desiredHeight; + wnd.Top = -10000; + wnd.Left = -10000; + wnd.Show(); + } else { + ctl.Measure(new Size(desiredWidth, desiredHeight)); + ctl.Arrange(new Rect(new Size(desiredWidth, desiredHeight))); + } + + RenderTargetBitmap bmp = new RenderTargetBitmap(300, 300, 96, 96, PixelFormats.Default); + bmp.Render(ctl); + + var encoder = new PngBitmapEncoder(); + + encoder.Frames.Add(BitmapFrame.Create(bmp)); + + var dlg = new SaveFileDialog(); + dlg.Filter = "*.png|*.png"; + if (dlg.ShowDialog() == true) { + using (Stream stm = File.OpenWrite(dlg.FileName)) { + encoder.Save(stm); + stm.Flush(); + } + } + + if (ctl is Window) { + var wnd = ctl as Window; + wnd.Close(); + } + } void ExitCommand_Executed(object sender, ExecutedRoutedEventArgs e) {