views:

482

answers:

3

I'm used to the old Winforms way of doing things.. Apparently WPF ListViews are full of... XmlElements? How would I do something as disable a ListViewItem?

foreach (XmlElement item in this.lvwSourceFiles.Items) { //disable?

}

+1  A: 

ListView is an ItemsControl. ItemsControl.Items does not return the child controls - it returns the items - that is, objects that you have added to the ListView, either directly, or via data binding. I guess in this case you have bound your ListView to some XML, right?

ListViewItem (and other classes like it - e.g. ListBoxItem for ListBox) is called an "item container". To retrieve an item container for a given item, you should do this:

ListView lv;
...
foreach (object item in lv.Items)
{
   ListViewItem lvi = (ListViewItem)lv.ItemContainerGenerator.ContainerFromItem(item);
}
Pavel Minaev
KevinDeus
A: 

You need to access the ListViewItem that represents the data item. You can achieve that through the ItemContainerGenerator

foreach (object item in this.lvwSourceFiles.Items)
{
    UIElement ui = lvwSourceFiles.ItemContainerGenerator.ContainerFromItem(item) as UIElement;
    if (ui != null)
        ui.IsEnabled = false;
}
Thomas Levesque
A: 

You can Perform that In XAML Easily

Emad Samy