c# - Binding generic ObservableCollection to ItemsSource of Listview, kills XAML Designer and Visual Studio -
when app launches, i'm setting datacontext of window such:
<window.datacontext> <vm:defaultviewmodel /> </window.datacontext>
then bind observablecollection listview later on with:
<listview margin="10" minheight="0" borderthickness="0" itemssource="{binding clients}"> <listview.view> <gridview> <gridviewcolumn header="client id" width="85" displaymemberbinding="{binding clientid}"/> <gridviewcolumn header="client name" width="220" displaymemberbinding="{binding clientname}"/> <gridviewcolumn header="branch" width="60" displaymemberbinding="{binding branch}" /> <gridviewcolumn header="client number" width="125" displaymemberbinding="{binding clientnumber}"/> <gridviewcolumn header="fed id" width="75" displaymemberbinding="{binding fedid}"/> <gridviewcolumn header="account manager" width="155" displaymemberbinding="{binding accountmanager}"/> <gridviewcolumn header="region" width="61" displaymemberbinding="{binding region}"/> </gridview> </listview.view> </listview>
that client list queried upon startup , set in default view model's constructor. problem application doesn't launch - client list bound , visible in xaml designer! , brings visual studio halt in general. what's issue here?
edit: here how data being bound (getclients runs query populates results observablecollection) -
public class defaultviewmodel : inotifypropertychanged { public defaultviewmodel() { _clients = datasource.getclients(); } private observablecollection<client> _clients; public observablecollection<client> clients { { return _clients; } set { set(ref _clients, value); } } public void raisepropertychanged([callermembername]string propertyname = null) { propertychanged?.invoke(this, new propertychangedeventargs(propertyname)); } public bool set<t>(ref t storage, t value, [callermembername]string propertyname = null) { if (equals(storage, value)) return false; storage = value; raisepropertychanged(propertyname); return true; } public event propertychangedeventhandler propertychanged; }
and here getclients function:
public static observablecollection<client> getclients() { var clients = new observablecollection<client>(); var query = file.readalltext(@"file_path"); using (var cn = new oledbconnection(pia_connection_string)) { var cmd = new oledbcommand(query, cn); cn.open(); using (var reader = cmd.executereader()) { while (reader.read()) { var client = new client { clientid = int.parse(reader[0].tostring()) }; clients.add(client); } } } return clients; }
Comments
Post a Comment