在Windows Phone 7中禁用列表框项目?

时间:2012-05-10 07:33:21

标签: windows-phone-7

我正在使用Windows Phone 7平台。

我在列表框中显示一年的月亮。

现在我想在列表框中仅启用当前月份,所有前几个月都应该禁用。下面是在listobx中填充一年中几个月的代码。

Listboxobject.ItemsSource = globalobject.Getmonths;

公开名单Getmonths

        monthlist.Add("January");
        monthlist.Add("February");
        monthlist.Add("March");
        monthlist.Add("April");
        monthlist.Add("May");
        monthlist.Add("June");
        monthlist.Add("July");
        monthlist.Add("August");
        monthlist.Add("September");
        monthlist.Add("October");
        monthlist.Add("November");
        monthlist.Add("December");
        return monthlist;

2 个答案:

答案 0 :(得分:0)

对于listbos中的每个项目,即对于每个listboxitem,它都有一个名为IsEnabled的属性。它是一个bool proprty。您可以将其设置为false以禁用它。

答案 1 :(得分:0)

这是你必须做的。请注意,我没有设置ItemSource,只是逐个添加ListBoxItems。如果要使用项禁用功能,则添加ListBoxItems而不是字符串很重要。如果您有任何问题,我可以向您发送解决方案。

        DateTime dt = DateTime.Today;
        DateTime dt2 = new DateTime();

        for (int i = 0; i < 12; i++) {
            string mname = dt2.ToString("MMMM");
            ListBoxItem LBI = new ListBoxItem();
            LBI.Content = mname;
            if (dt.Month > dt2.Month)
                LBI.IsEnabled = false;
            Listboxobject.Items.Add(LBI);
            dt2 = dt2.AddMonths(1);
        }