I have a ListView
that contains several types of custom UserControls
.
The project requires that some of them must be non-clickable, so I would like to disable them, but JUST THEM.
Those items will be enabled/disabled depending on the value of a custom property.
I've tried to set the ListViewItem.IsEnabled
property to false
, but it ain't worked, and the other solutions I've found around make no sense to me...
I let a sample of the code:
XAML
<ListView x:Name="homeLW"
Margin="0,5,0,0"
ItemClick="homeLW_ItemClick"
IsItemClickEnabled="True"
HorizontalAlignment="Center"
ItemsSource="{Binding Source}">
Where Source
is a ObservableCollection<UserControl>
.
The problem is that I can't get the items of the ListView
as ListViewItems
, but as the UserControl
type:. When executing this:
foreach(ListViewItem lwI in homeLW.Items)
{
//CODE
}
I get:
System.InvalidCastException: Unable to cast object of type UserControl.Type to type Windows.UI.Xaml.Controls.ListViewItem.
Anyone know how could I make it?
Thanks in advance :)