c# - Converting TextBox.Text to Int. (No-Code Behind) -
i have not found solution on internet solve issue. hope can me.
so title says. have this
public mycommand champion { { return new mycommand((id) => { championbyid(id); }); } set { _champion = value; } } private async void championbyid(object id) { _staticriotapi.getchampion(region.euw, (int)id); } which bind button in view, looks this, pretty simple.
<button content="search id" command="{binding champion}" commandparameter="{binding elementname=championid}"> </button> <textbox grid.row="0" grid.column="1" name="championid"></textbox> the method getchampion needs id of champion, enter in text box, passed "id", tried casting int. this(like above) , this
" exception of type 'system.invalidcastexception' occurred in riotapiapplication.exe not handled in user code additional information: specified cast not valid."
i tried convert.toint32(id) this:
unable cast object of type 'system.windows.controls.textbox' type 'system.iconvertible'.
so next try tried including converter takes input of textbox , convert integer. eg. "aatrox" == 266, looks this. (i know isnt best solution, want work first)
switch (value string) { case "aatrox": value = 266; break; } return value; but still same issue. tried creating new mycommand class generic returned integer , still no hope.
can find solution or me right way. kinda stuck , don't know do. can write method takes string, defeat purpose of using library.
you referencing wrong object commandparameter - pass textbox command instead of containing textelement. in order fix this, have use "path" syntax in commandparameter binding:
<button content="search id" command="{binding champion}" commandparameter={binding elementname=championid, path=text}"> </button> <textbox grid.row="0" grid.column="1" name="championid"></textbox>
Comments
Post a Comment