按钮的标签属性 [英] Tag attribute of button
问题描述
嘿大家,
我看到了一个名为Tag的属性按钮。谁能告诉我应该如何以及何时使用Tag属性。
I have seen a property called Tag for the buttons . Could anyone tell me how, when and where the Tag property should be used.
推荐答案
标签属性只是一个可以存储几乎所有内容的对象。
The tag property is just an object you can store almost anything in.
执行以下操作:
//在标签属性中输入它 - 无论它有意义 - 初始化器,加载,xaml等等
yourButton.Tag = www.yoursite.com ;
// enter this in the tag property wherever it makes sense - initializer, load, xaml, etc
yourButton.Tag = www.yoursite.com;
然后在您的点击活动中,您只需访问标签属性
then in your click event you can just access the tag propery
string url =((Button)sender).Tag.ToString();
string url = ((Button)sender).Tag.ToString();
转换为uri并进行正常的点击方法。
convert to uri and go about your normal click method.
或你可以存储uri。
我认为它对你有帮助。
这篇关于按钮的标签属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!