c# - MouseRightClick on ListBox crashes the app -
when mouse right click on empty listbox, whole app crashes , don't know how debug this, put try-catch
, on.
have encountered such problem? ideas on how solve issue?
here's xaml on listbox:
<listbox x:name="lststat" horizontalalignment="left" height="129" margin="10,10,0,0" verticalalignment="top" width="330" fontsize="16" itemssource="{binding statisticsqueries}" cursor="arrow"> <listbox.itemtemplate> <datatemplate> <label content="{binding path=name}" fontweight="medium" fontsize="18" fontfamily="helveticaneuecyr"/> </datatemplate> </listbox.itemtemplate> </listbox>
maybe xaml somehow wrong?
update
here're bindings .cs
public observablecollection<query> statisticsqueries { get; private set; } private void fillstatisticslist() { const string statsquery = "select * cached_queries is_statistics true;"; var connection = new mysqlconnection(databasemodel.connectionstring); connection.open(); var cmd = new mysqlcommand(statsquery, connection); cmd.executenonquery(); var reader = cmd.executereader(); cmd.commandtype = commandtype.text; statisticsqueries = new observablecollection<query>(); while (reader.read()) { statisticsqueries.add(new query { id = reader["id"].tostring(), autoschool = reader["autoschool"].tostring(), isstatistics = reader["is_statistics"].tostring(), name = reader["query_name"].tostring(), text = reader["query_text"].tostring() }); } connection.close(); }
and here's on window_loaded
event:
await task.run(() => fillstatisticslist());
that's code connected listbox, has nothing rightmouseclick... why doesn't crash on other click or something?
try following: include try-catch block , show error message:
private void fillstatisticslist() { try { const string statsquery = "select * cached_queries is_statistics true;"; var connection = new mysqlconnection(databasemodel.connectionstring); connection.open(); var cmd = new mysqlcommand(statsquery, connection); cmd.executenonquery(); var reader = cmd.executereader(); cmd.commandtype = commandtype.text; statisticsqueries = new observablecollection<query>(); while (reader.read()) { statisticsqueries.add(new query { id = reader["id"].tostring(), autoschool = reader["autoschool"].tostring(), isstatistics = reader["is_statistics"].tostring(), name = reader["query_name"].tostring(), text = reader["query_text"].tostring() }); } connection.close(); } catch (exception ex) { messagebox.show(ex.message); } }
hope may help.
Comments
Post a Comment