@ -1,9 +1,18 @@
@@ -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
@@ -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
@@ -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 = 3 0 0 ;
int desiredHeight = 3 0 0 ;
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 = - 1 0 0 0 0 ;
wnd . Left = - 1 0 0 0 0 ;
wnd . Show ( ) ;
} else {
ctl . Measure ( new Size ( desiredWidth , desiredHeight ) ) ;
ctl . Arrange ( new Rect ( new Size ( desiredWidth , desiredHeight ) ) ) ;
}
RenderTargetBitmap bmp = new RenderTargetBitmap ( 3 0 0 , 3 0 0 , 9 6 , 9 6 , 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 )
{