Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can write a wrapper around xamDataGrid that has a dependencyproperty called filename. The viewmodel can then bind to this property. When the xamDataGrid detects a change on the filename property it can then execute the code you suggested. Afterwards reset the filename property for further notification.</p> <p>This solution keeps out the code from you code behind and makes the xamDataGrid responsible for exporting its data.</p> <p>-------edit---------</p> <p>A second solution can make use of the MVVM light messenger class. In stead of declaring a dependency property, make your wrapper listen to a message. When the viewmodel sends the message (which could for example have the filename as parameter) the wrapper can then execute the code.</p> <p>eg</p> <pre><code>public class ExportableXamDataGrid: XamDataGrid { public ExportableXamDataGrid():base() { Messenger.Default.Register&lt;string&gt;(this,"ExportExcel",ExportFile); } private void ExportFile(string file) { xamDataGridExcelExporter.xamDataGridExcelExporter xamDataGridExcelExporter1 = new xamDataGridExcelExporter.xamDataGridExcelExporter(); xamDataGridExcelExporter1.Export(**this.xamDataGrid1**, @"C:\Excel\ExportFile.xls"); } } </code></pre> <p>Then in your viewmodel you can do:</p> <pre><code> Messenger.Default.Send(@"C:\Excel\ExportFile.xls","ExportExcel"); </code></pre> <p>There are many solutions to your problem, all of which you do not have to start writing logic in your view.</p> <p><a href="http://www.lucbos.net/2011/06/using-codebehind-in-mvvm.html" rel="nofollow">http://www.lucbos.net/2011/06/using-codebehind-in-mvvm.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload