在 C# 中添加单选按钮和评级视图
Adding radiobuttons and ratingview in C#
在 foor 循环中,我需要根据 obj 值创建一个项目:
例如:
for(int i=0;i<mylist.count;i++)
if(mylist[i].type==1)
{
//create radiobutton
}
else if(mylist[i].type==2)
{
//create ratingview
}
等等
如果在 C# 中创建了多个单选按钮,我如何区分单选按钮和评级视图?
比如如何为每个创建的项目添加标签或 ID?
解法:
如果找不到标签 属性,只需创建一个:
public void test() {
for (int i = 0; i < 10; i++)
if (i<5)
{
//create radiobutton
radiobutton btn = new radiobutton
{
Text = "Click to Rotate Text!",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
tag = i
};
Console.WriteLine(btn.tag);
}
else if (i > 2)
{
//create ratingview
}
}
public class radiobutton : Button
{
public int tag;
}
在 foor 循环中,我需要根据 obj 值创建一个项目:
例如:
for(int i=0;i<mylist.count;i++)
if(mylist[i].type==1)
{
//create radiobutton
}
else if(mylist[i].type==2)
{
//create ratingview
}
等等
如果在 C# 中创建了多个单选按钮,我如何区分单选按钮和评级视图? 比如如何为每个创建的项目添加标签或 ID?
解法:
如果找不到标签 属性,只需创建一个:
public void test() {
for (int i = 0; i < 10; i++)
if (i<5)
{
//create radiobutton
radiobutton btn = new radiobutton
{
Text = "Click to Rotate Text!",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
tag = i
};
Console.WriteLine(btn.tag);
}
else if (i > 2)
{
//create ratingview
}
}
public class radiobutton : Button
{
public int tag;
}