wpf - Window is loading first then Command is firing when I am using Interactivity -
i using following code call loadcommand in viewmodel during loading window.
<code> <i:interaction.triggers> <i:eventtrigger eventname="loaded"> <i:invokecommandaction command="{binding loadcommand}"/> </i:eventtrigger> </i:interaction.triggers> </code> but seeing window loading before loadcommand fires.so code have put in loadcommand
public icommand loadcommand { { if (_loadcommand == null) { _loadcommand = new relaycommand( param => this.load(), param => this.canload ); } return _loadcommand; } } list<match> matchlist; observablecollection<match> _matchobscollection; public observablecollection<match> matchobscollection { { return _matchobscollection; } set { _matchobscollection = value; onpropertychanged("matchobscollection"); } } public void load() { matchlist = matchbll.getmatch(); } bool canload { { return true; } } fires after window loads.if put code in constructor of viewmodel fires before window loads. want know how in mvvm can make command fire first , load window second. thanking in advance.
the problem seems window has loaded before viewmodel has been instantiated , bound datacontext. solution instantiate viewmodel before view.
var vm = new myviewmodel(); var view = new myview(); view.datacontext = vm; view.show(); don't use framework instantiates view , "discovers" applicable viewmodel, @ least not in case.
Comments
Post a Comment