c# - "Value does not fall in expected range" List collection and not in Observable collection -


this working code,

private observablecollection<user> _users; public observablecollection<user> users  {       { return _users; }       set { _users = value; raisepropertychanged(()=> users); }  }  users = new observablecollection<user>(); (int = 1; <= 10; i++) {     users.add(new user()     {         address_line_1 = "test address",         address_line_2 = "test address 2",         first_name = "test name " + i,         surname = "test surname " +i,         date_of_birth = datetime.now.date,         gender = "m",         mobile_phone_number = "+1100000",         email_address = "test@email.com",         last_modified = datetime.now,         login_name ="operator.domain.com",         itemindex = users.count +1      }); } 

earlier using

private list<user> _users; public list<user> users  {      { return _users; }      set { _users = value; raisepropertychanged(()=> users); }  }  users = new list<user>(); (int = 1; <= 10; i++) {     users.add(new user()     {         address_line_1 = "test address",         address_line_2 = "test address 2",         first_name = "test name " + i,         surname = "test surname " +i,         date_of_birth = datetime.now.date,         gender = "m",         mobile_phone_number = "+9100000",         email_address = "test@email.com",         last_modified = datetime.now,         login_name ="operator1.domain.com",         itemindex = users.count +1     }); } 

and continuously getting following exception message, when try bind datatemplate in xaml

value not fall within expected range.  

stack trace null :(

in addition, if take list variable , add values , assign shallow copy of list above list, code give me desired result, again going around.

this datatemplate

<datatemplate>             <grid margin="-8,-10,-8,-10" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                 <grid.columndefinitions>                     <columndefinition width="*"></columndefinition>                     <columndefinition width="*"></columndefinition>                     <columndefinition width="*"></columndefinition>                     <columndefinition width="*"></columndefinition>                     <columndefinition width="*"></columndefinition>                     <columndefinition width="*"></columndefinition>                 </grid.columndefinitions>                 <border grid.column="0" style="{staticresource borderstyleforadmin}" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                     <stackpanel orientation="horizontal">                         <!--<border borderbrush="gray" borderthickness="0.3" visibility="{binding isselecteditem, mode=twoway, converter={staticresource controlvisibiltyofselectediteminlistbox}}">                             <textblock text="{staticresource arrowglyph}" foreground="black" verticalalignment="center" horizontalalignment="right"></textblock>                         </border>-->                         <textblock style="{staticresource textblockcell}" text="{binding surname}"></textblock>                     </stackpanel>                 </border>                 <border grid.column="1" style="{staticresource borderstyleforadmin}" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                     <textblock style="{staticresource textblockcell}" text="{binding first_name}"></textblock>                 </border>                 <border grid.column="2" style="{staticresource borderstyleforadmin}" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                     <textblock style="{staticresource textblockcell}" horizontalalignment="stretch">                         <run text="{binding address_line_1}"></run><linebreak></linebreak>                          <run text="{binding address_line_2}"></run>                     </textblock>                 </border>                 <border grid.column="3" style="{staticresource borderstyleforadmin}" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                     <textblock style="{staticresource textblockcell}" text="{binding date_of_birth}"></textblock>                 </border>                 <border grid.column="4" style="{staticresource borderstyleforadmin}" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                     <textblock style="{staticresource textblockcell}" text="{binding email_address}"></textblock>                 </border>                 <border grid.column="5" style="{staticresource borderstyleforadmin}" background="{binding itemindex, converter={staticresource alternaterowbackgroundconverter}}">                     <textblock style="{staticresource textblockcell}" text="{binding mobile_phone_number}"></textblock>                 </border>             </grid>         </datatemplate> 

though, observable collection works me wondering why list giving me exception, unable figure out what's actual reason behind scene. in advance.

only thing bugs me out here "raisepropertychanged" used observablecollection or @ least must inherit inotifypropertychanged interface. in second implementation list not getting "raisepropertychanged" method. consider list declaration as:

private list<user> _users; public list<user> users  {      { return _users; }      set { _users = value;}  } 

i think should resolve error. note doing not raise propertychanged event whenever state of object changes (added, removed, , modified) point want notify underlying collection or container state has changed.

for more info read: list vs observablecollection vs inotifypropertychanged in silverlight


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -