Printing with MVVM


hi, i'm having trouble mvvm pattern build tool printing functions.

here's i've done, simplified:

1st created silverlight class library, childwindowtest, created mychildwindow (the view):

<controls:childwindow       x:class="childwindowtest.mychildwindow"      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       xmlns:controls="clr-namespace:system.windows.controls;assembly=system.windows.controls"      width="400" height="300"       title="mychildwindow">            <grid x:name="layoutroot" margin="2">          <grid.rowdefinitions>              <rowdefinition />              <rowdefinition height="25" />          </grid.rowdefinitions>                    <grid x:name="contentarea" grid.row="0">              <!-- rest of window! -->          </grid>                    <stackpanel x:name="inferiormenu" grid.row="1" orientation="horizontal" horizontalalignment="right">              <button content="pop message" command="{binding popper}" commandparameter={binding contentarea} margin="0,0,5,0"/>              <button content="close" click="close"/>          </stackpanel>      </grid>  </controls:childwindow>      


using system;  using system.collections.generic;  using system.linq;  using system.net;  using system.windows;  using system.windows.controls;  using system.windows.documents;  using system.windows.input;  using system.windows.media;  using system.windows.media.animation;  using system.windows.shapes;    namespace childwindowtest  {      public partial class mychildwindow : childwindow      {          public mychildwindow()          {              initializecomponent();              inferiormenu.datacontext = new viewmodels.inferiorbarviewmodel();          }            private void close(object sender, routedeventargs e)          {              this.dialogresult = false;          }      }  }    



then added class library viewmodel , refered on childwindowtest project:

using system;  using system.net;  using system.windows;  using system.windows.controls;  using system.windows.documents;  using system.windows.ink;  using system.windows.input;  using system.windows.media;  using system.windows.media.animation;  using system.windows.shapes;  using system.componentmodel;    namespace viewmodels  {      public class inferiorbarviewmodel : inotifypropertychanged      {          public event propertychangedeventhandler propertychanged;            public void onpropertychanged(string propertyname)          {              if (propertychanged != null)                  propertychanged(this, new propertychangedeventargs(propertyname));          }            public printcommand popper { get; set; }            public inferiorbarviewmodel()          {              popper = new printcommand(this);          }      }  }  



using system;  using system.net;  using system.windows;  using system.windows.controls;  using system.windows.documents;  using system.windows.ink;  using system.windows.input;  using system.windows.media;  using system.windows.media.animation;  using system.windows.shapes;  using system.windows.printing;    namespace viewmodel  {      public class printcommand : icommand      {          inferiorbarviewmodel parentviewmodel;          printdocument printdocument;          private bool canxecute = true;            public event eventhandler canexecutechanged;            public bool canexecute(object parameter)          {              return canxecute;          }            public void execute(object parameter)          {              printdocument.beginprint += (s, args) =>              {                  canxecute = false;              };              printdocument.printpage += (s, args) =>              {                  args.pagevisual = parameter grid;                  args.hasmorepages = false;              };              printdocument.endprint += (s, agrs) =>              {                  canxecute = true;              };              printdocument.print("test");          }            public printcommand(inferiorbarviewmodel viewmodel)          {              parentviewmodel = viewmodel;              printdocument = new printdocument();          }      }  }  




that compiled creates childwindowtest.dll. test if working created yet solution, project called dumbapplication calls dll compiled on previous solution:


<usercontrol x:class="dumbapplication.mainpage"      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"      mc:ignorable="d"      d:designheight="300" d:designwidth="400">        <grid x:name="layoutroot" background="white">          <button content="click me!" horizontalalignment="center" verticalalignment="center" click="button_click"/>      </grid>  </usercontrol>  


using system;  using system.collections.generic;  using system.linq;  using system.net;  using system.windows;  using system.windows.controls;  using system.windows.documents;  using system.windows.input;  using system.windows.media;  using system.windows.media.animation;  using system.windows.shapes;    namespace dumbapplication  {      public partial class mainpage : usercontrol      {          childwindowtest.mychildwindow newchildwindow = new childwindowtest.mychildwindow();            public mainpage()          {              initializecomponent();          }            private void button_click(object sender, routedeventargs e)          {              newchildwindow.show();          }      }  }  



when run dumbapplication, calls childwindow, function of printing never works!

does knows if there's way make work properly?


ok, i'll bite.  printing?


(i can't spot in code printing)



Silverlight  >  MVVM / ViewModel Pattern with Silverlight



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........