I am trying to set the isEnabled property to false for a ListBox Item. Included in the code is a some xaml that shows how it is done in the designer, but I need to do it in code.
Here is my code:
string[] names = { "alpha", "beta", "gamma", "delta" };
for (int i = 0; i < names.Length; i++)
{
listBox1.Items.Add(names[i].ToString());
//set items 2 & 4 to isEnabled=false
// <ListBoxItem Content="beta" IsEnabled="False" /> xaml code
// My Attempt, does not compile, cannot be used like a method
// listBox1.isEnabled(2,false);
}
This is for a WindowsPhone7 app using C#/Silverlight.
How about:
listBox1.Items.Add(new ListBoxItem() { Content = "one", IsEnabled = true });
listBox1.Items.Add(new ListBoxItem() { Content = "two", IsEnabled = false});
Then when you want to get the selected item you can do
void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItem selectedItem = listbox1.SelectedItem;
stirng content = selectedItem.Content.ToString()
}
如果要为第三项设置它,例如:
listBox1.Items[2].IsEnabled = false;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.