mvvm light - WPF Close Window Closes Source Window. Why? -


the problem having little hard describe, please hear out.

i'm opening 1 window , trying close second one. if use command of inputbindings of second one, second 1 closes fine. if call close directly closes both first , second window. expect code scenario.

wpf: window1view (key part)

<grid>   <button content="button" command="{binding rptkeydowncommand}" /> </grid> 

window1viewmodel: (shortened listing)

using galasoft.mvvmlight.command; var _runcommand = new relaycommand(() => run(), () => canrun());      public void run()     {         var v = new window2();         var vm = new window2viewmodel();         vm.requestclose += v.close;         v.datacontext = vm;         v.showdialog();     }      public event action requestclose;      var _closecommand = new relaycommand(() => close(), () => canclose());     public void close()     {         if (requestclose != null)             requestclose();     } 

wpf: window2view

<window.inputbindings>     <keybinding key="escape" command="{binding closecommand}" /> </window.inputbindings>     <textbox text="hello">         <i:interaction.triggers>             <i:eventtrigger eventname="previewkeydown">                 <cmd:eventtocommand                       command="{binding close2command, mode=oneway}"                      passeventargstocommand="true" />             </i:eventtrigger>         </i:interaction.triggers>     </textbox> 

window2viewmodel: (has same close command plus eventtocommand end point)

var _close2command = new relaycommand<keyeventargs>(p => close2(p), p => canclose2(p));      public void close2(keyeventargs e)     {         if (e.key == key.escape)             close();               <- here closes both window1view , window2view?     } 

see this answer on other thread solution.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -