c# - ListView SelectedItems binding: why the list is always null -


i'm developing uwp app, mvvm light , behaviours sdk. defined multi selectable listview:

<listview     x:name="memberstoinvitelist"     ismultiselectcheckboxenabled="true"     selectionmode="multiple"     itemssource="{binding contacts}"     itemtemplate="{staticresource membertemplate}">  </listview> 

i'd like, button binded mvvm-light relaycommand, obtain list selected items:

<button     command="{binding addmemberstoevent}"     commandparameter="{binding elementname=memberstoinvitelist, path=selecteditems}"     content="ok"/> 

the relaycommand (of mvvm-light framework):

private relaycommand<object> _addmemberstoevent; public relaycommand<object> addmemberstoevent {         {         return _addmemberstoevent             ?? (_addmemberstoevent = new relaycommand<object>(                (selectedmembers) =>                {                    // test                    // selectedmembers null!                }));     } } 

i put breakpoint inside command, , notice selectedmembers null, although select various items. console output don't see binding error or else.

also, if pass commandparameter whole list, , put breakpoint inside command's definition, notice can't access selecteditems nor selecteranges value.

<datatemplate x:name="membertemplate">      <viewbox maxwidth="250">         <grid width="250"               margin="5, 5, 5, 5"               background="{staticresource mylightgray}"               borderbrush="{staticresource shadowcolor}"               borderthickness="0, 0, 0, 1"               cornerradius="4"               padding="5">              <grid.columndefinitions>                 <columndefinition width="auto" />                 <columndefinition width="1*" />             </grid.columndefinitions>              <grid grid.column="0"                   width="45"                   height="45"                   margin="5,0,5,0"                   verticalalignment="center"                   cornerradius="50">                  <grid.background>                     <imagebrush alignmentx="center"                                 alignmenty="center"                                 imagesource="{binding image.url,                                                       converter={staticresource nullgroupimageplaceholderconverter}}"                                 stretch="uniformtofill" />                 </grid.background>              </grid>              <textblock grid.column="1"                        margin="3"                        verticalalignment="center"                        foreground="{staticresource foregroundtextoverbodycolor}"                        style="{staticresource lighttext}"                        text="{binding alias}" />          </grid>     </viewbox>  </datatemplate> 

what's reason? how can obtain such list?

one of solutions pass selecteditems listview in viewmodel (with relaycommands) described in igralli's blog.

pass listview selecteditems viewmodel in universal apps

try following code selected objects parameter.

    private relaycommand<ilist<object>> _addmemberstoevent;     public relaycommand<ilist<object>> addmemberstoevent     {                 {             return _addmemberstoevent                    ?? (_addmemberstoevent = new relaycommand<ilist<object>>(                        selectedmembers =>                        {                            list<object> memberslist = selectedmembers.tolist();                        }));         }     } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -