c# - How do I make the object(ViewList.SelectedItems) provided as a parameter to Command executed in response to an event? -


this seems fundamental feel must missing in search solution.

i have viewmodel has observablecollection< excelfield> property used itemssource listview in associated view.

i have added eventtocommand item in view accesses relaycommand pass command method(excellistchanged) in viewmodel parameter set selecteditems property in viewlist.

in viewmodel construct list containing items have been selected. in debugger able examine contents of object parameter , validate indeed holds information access. unfortunately have not been able find key enables me access data in parameter object, have tried casting, assigning, changeto , more. cast , changeto exception unknown conversion or similar. thought since object listview.selecteditems(?) might able cast flavor of appears not doable outside of listview object.

a simple solution great, complicated 1 okay , convoluted 1 painful.

thanks guidance.

here code pieces

the data structure

public struct excelfield {     private int index;     public int index     {         { return index; }         private set { index = value; }     }     private string fieldname;     public string fieldname     {         { return fieldname; }         private set { fieldname = value;  }     }      public excelfield(int ndx, string name)     {         index = ndx;         fieldname = name;     } } 

pieces viewmodel

    observablecollection<excelfield> fieldnames;     public observablecollection<excelfield> fieldnames     {                 {             return fieldnames;         }         set         {             fieldnames = value;             onpropertychanged("fieldnames");         }     } 
       alllistchanged = new relaycommand(args => excellistchanged(args)); 
    relaycommand alllistchanged;     public relaycommand alllistchanged     {                 {             return alllistchanged;         }     } 
    private void excellistchanged(object parameter)     {         var whata = parameter.gettype();         return;     } 

and view pieces

<usercontrol.resources>     <viewmodel:excelmapperviewmodel x:key="excelmapperviewmodeldatasource" d:isdatasource="true"/>     <datatemplate x:key="excelfieldtemplate">         <stackpanel>             <textblock text="{binding fieldname, mode=oneway}"/>             <textblock text="{binding index, mode=oneway}"/>         </stackpanel>     </datatemplate> </usercontrol.resources>       <listview x:name="allfields" grid.column="1" grid.row="1" grid.rowspan="3"         itemssource="{binding fieldnames}"         itemtemplate="{staticresource excelfieldtemplate}"         >         <listview.itemcontainerstyle>             <style targettype="listviewitem">                 <setter property="isselected" value="{binding isselected}" />             </style>         </listview.itemcontainerstyle>         <listview.view>             <gridview>                 <gridviewcolumn displaymemberbinding="{binding index}" header="index"/>                 <gridviewcolumn displaymemberbinding="{binding fieldname}" header="field name"/>             </gridview>         </listview.view>         <i:interaction.triggers>             <i:eventtrigger eventname="selectionchanged">                 <custom:eventtocommand                     command="{binding alllistchanged, mode=oneway}"                     commandparameter="{binding elementname=allfields, path=selecteditems}"                 />             </i:eventtrigger>         </i:interaction.triggers>     </listview> 

i set breakpoint on excellistchanged , run code. when select items in listview excellistchanged triggered , can examine parameter object. able see number of entries selected count on parameter , array of excelfield items appropriate information fields within structure.

so how access information can see in debugger programmatically?

since selecteditems ilist http://msdn.microsoft.com/en-us/library/system.collections.ilist(v=vs.110).aspx can iterate through it...

   private void excellistchanged(object parameter) {     ilist iconverted= parameter ilist;     if(iconverted!=null){       foreach(youknowthetypeofelements theelement in iconverted) {          dosomethingwith(theelement);       }     }     return; } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -