按钮的标签属性 [英] Tag attribute of button

查看:70
本文介绍了按钮的标签属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家,

 

我看到了一个名为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆