在C#中添加单选按钮和ratingview

问题描述 投票:0回答:1

在for循环中,我需要根据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#中创建了多个radiobutton,我如何区分radiobutton和ratingviews?就像我如何为每个项目创建标签或ID?

c# xamarin.forms radio-button rate
1个回答
1
投票

解:

如果找不到标签属性,只需创建一个:

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.