c# - How to set and get tag in xaml dynamically? -


while creating gui using xaml, created textbox tag this:

<textbox name="textbox" horizontalalignment="center" verticalalignment="center" margin="216,178,143,120" width="158"              tag="mytag"/>  

now want let user able change tag. that, looking kind of function of form:

textbox.settag( "user provided tag" ) 

so tag can changed one:

<textbox name="textbox" horizontalalignment="center" verticalalignment="center" margin="216,178,143,120" width="158"              tag="user provided tag"/>  

after searching internet quite while, didn't come practical solution. help? thanks.

you can use binding between 2 controls. user allowed enter tag value textbox. bind tag of second textbox text property of first textbox:

<textbox name="entertagtextbox" /> <textbox name="gettagtextbox" tag="{binding elementname=entertagtextbox, path=text}"/> 

to test added button in xaml:

<button height="25" click="button_click_1"/> 

in code behind retrieve tag value , display this:

private void button_click_1(object sender, routedeventargs e) {     string text = this.gettagtextbox.tag.tostring();     global::system.windows.forms.messagebox.show(text); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -