wpf - How to use the text of a routed command as button content -
i have button on view bound via routeduicommand command defined in viewmodel.
the xaml code excerpt view:
<button content="login" command="{binding login}" />
in view's codebehind add command binding viewmodel view's binding collection:
this.commandbindings.add( viewmodel.logincommandbinding );
the viewmodel implements command:
public class loginviewmodel:viewmodelbase { public icommand login { get; private set; } public commandbinding logincommandbinding { get; private set; } public loginviewmodel( ) { this.login = new routeduicommand( "login", "login", typeof( window ) ); this.logincommandbinding = new commandbinding( login, logincommandhandler, canexecutehandler ); } void logincommandhandler( object sender, executedroutedeventargs e ) { //put code here } void canexecutehandler( object sender, canexecuteroutedeventargs e ) { return true; } }
so command defined text , name both "login". button has content "login". there way use command's text button's content?
just bind name or text property in command, so:
<button x:name="btnname" command="{binding thisismycommand}" content="{binding thisismycommand.name}" /> <button x:name="btntext" command="{binding thisismycommand}" content="{binding thisismycommand.text}" />
Comments
Post a Comment