小智 9
您可以使用:
if (element is Grid)
{
}
else if (element is Label)
...
Run Code Online (Sandbox Code Playgroud)
如果您只有有限数量的类型要检查,请使用"as"运算符进行尝试,然后检查null.
Button button = control as Button;
if (button != null)
{
// this is a button)
}
...
Run Code Online (Sandbox Code Playgroud)
如果无法完成转换,则as运算符不会抛出异常.
编辑:如果你只是想要实现控件的样式,你应该看看<Style/>标签.
见这里的一个很好的例子
| 归档时间: |
|
| 查看次数: |
8569 次 |
| 最近记录: |