如何清空列表框内容c#?

如何清空列表框内容c#?,c#,silverlight,windows-phone-7,C#,Silverlight,Windows Phone 7,我有以下代码: public void LoadData1(String link) { string temp=""; int pos = 0; for (int x = 0, y = 0; x < link.Length; x++) //separate various code if (link[x] == 'y') { for (temp = ""

我有以下代码:

public void LoadData1(String link)
    {
        string temp="";
        int pos = 0;
        for (int x = 0, y = 0; x < link.Length; x++) //separate various code
            if (link[x] == 'y')
            {
                for (temp = ""; y < x; y++)
                    if(link[y]!='y')
                        temp += link[y];
                list[pos] = temp;
                pos++;
                y = x++;
            }
        string nota=list[0];
        for (int a = 0; a < list.Count() && list[a]!=null ; a++,nota=list[a])
        {
            string tempI = "";
            //immagine
            for (int x = 0; x < nota.Count(); x++)
            {
                if (nota[x] == 'p')
                    tempI += '+';
                else
                    tempI += nota[x];
            }

            //nome della pagina
            string temp1 = "";
            int c = tempI.Count();
            if (tempI.Count() > 2)
                if (tempI.ElementAt(2) == 'l') //sol
                {

                    for (int x = 0; x < c; x++)

                        if (x == 3 && tempI.ElementAt(3) == 'd')
                            temp1 += '#';
                        else
                            temp1 += tempI.ElementAt(x);
                }
                else
                {

                    for (int x = 0; x < c; x++)

                        if (x == 2 && tempI.ElementAt(2) == 'd')
                            temp1 += '#';
                        else
                            temp1 += tempI.ElementAt(x);
                }
            else
                temp1 = tempI;

            this.Temp.Add(new ImageText() { Text = temp1, linkImage = "/Accordi/"+tempI+".png" });
        }
        this.IsDataLoaded1 = true;
        this.Temp = new ObservableCollection<ImageText>();
    }
public void LoadData1(字符串链接)
{
字符串temp=“”;
int pos=0;
for(intx=0,y=0;x2)
if(tempI.ElementAt(2)='l')//sol
{
对于(int x=0;x
这将填充由文本和图像组成的列表框。但是我有一个问题:当我用3个元素填充列表框时(例如),一切正常,但是当我再次调用用2个元素填充列表框的函数时,列表框显示call的两个元素,在第三个空格显示我上次调用的元素!!我怎样才能解决这个问题?
listbox是通过temp绑定的,字符串链接包含一系列代码,如“DoyDodyRey”

每次加载数据时都会设置“n”元素,但对已经存在的元素不做任何处理,因此如果在前一次调用中有第三个元素,在后续调用中只有两个,那么第三个元素仍然存在

这只是一个先清理的问题,或者之后移除多余的项目。很难从您的代码中准确地看到发生了什么,但我认为调用方法顶部的
list.Clear()
可能会完成这项工作


如果您只想删除多余的项目,我认为您应该能够添加
while(list.Count()>=pos)list.remove(pos)就在您的第一个for循环之后。

您不能在开始时声明列表,使其为空吗

List<string> yourlist = new List<string>();
列表中的第一篇文章将获取您的列表[0],依此类推


希望这有点帮助:)

哦,我的上帝,谢谢!!我没有看到列表不是每次都被日化的哦,我的上帝,谢谢!!我没有看到列表不是每次都被序列化
yourlist.add(temp)