Hi all. I'm pretty new to WPF so excuse me for any dumb question...
I have a ListView with three columns that is binded to a XmlDataProvider source like the following:
<XmlDataProvider x:Key="Properties" XPath="/Info">
<x:XData>
<Info xmlns="">
<Property Name="Text" Value=""/> <!--0-->
<Property Name="Tooltip" Value=""/> <!--1-->
<Property Name="Enable" Value=""/> <!--2-->
<Property Name="Visible" Value=""/> <!--3-->
<Property Name="Focus" Value=""/> <!--4-->
<Property Name="Selected" Value=""/> <!--5-->
<Property Name="Count" Value=""/> <!--6-->
<Property Name="Item" Value=""/> <!--7-->
<Property Name="SelectedText" Value=""/> <!--8-->
<Property Name="SelectedIndex" Value=""/> <!--9-->
<Property Name="Complete" Value=""/> <!--10-->
</Info>
</x:XData>
</XmlDataProvider>
The ListView is defined as following:
<ListView Name="lstProperties" Margin="55 0 0 0" Style="{DynamicResource TsListView}"
Grid.Row="2" Grid.RowSpan="7" Grid.ColumnSpan="4"
ItemsSource="{Binding Source={StaticResource Properties}, XPath=Property}"
ItemContainerStyle="{DynamicResource TsListViewItem}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
SelectionMode="Single" IsEnabled="False"
SelectionChanged="propertySelected"
>
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn CellTemplate="{StaticResource FirstCell}" Width="25" />
<GridViewColumn Header="Property" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Style="{DynamicResource TsLabel}" Height="25" Width="115" Content="{Binding XPath=@Name}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Value" Width="130">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Style="{DynamicResource TsHelperTextBox}"
Height="20" Width="115" Text="{Binding XPath=@Value}"
IsEnabled="{Binding ElementName=rbTypeAssert, Path=IsChecked}" GotFocus="gridTextBox_GotFocus" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
What I want to do now is fairly simple: I just want to enable/disable some of the ListViewItems. The only way I found to get ListViewItems is through the following method:
lstProperties.ItemContainerGenerator.ContainerFromIndex(index)
This makes me a little uncomfortable. I should be getting the Items through the name property of Property. Is there anyway to do this? I'm also having problems when I try to do this right after the window is initialized. I get a NullReferenceException when trying to disable one of these ListViewItems. It seems that right after the window is rendered the binding is not done yet.