Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get binded ListboxItems from ListView in WPF
    primarykey
    data
    text
    <p>I'm pretty new to WPF so excuse me for any dumb question...</p> <p>I have a ListView with three columns that is binded to a XmlDataProvider source like the following:</p> <pre><code> &lt;XmlDataProvider x:Key="Properties" XPath="/Info"&gt; &lt;x:XData&gt; &lt;Info xmlns=""&gt; &lt;Property Name="Text" Value=""/&gt; &lt;!--0--&gt; &lt;Property Name="Tooltip" Value=""/&gt; &lt;!--1--&gt; &lt;Property Name="Enable" Value=""/&gt; &lt;!--2--&gt; &lt;Property Name="Visible" Value=""/&gt; &lt;!--3--&gt; &lt;Property Name="Focus" Value=""/&gt; &lt;!--4--&gt; &lt;Property Name="Selected" Value=""/&gt; &lt;!--5--&gt; &lt;Property Name="Count" Value=""/&gt; &lt;!--6--&gt; &lt;Property Name="Item" Value=""/&gt; &lt;!--7--&gt; &lt;Property Name="SelectedText" Value=""/&gt; &lt;!--8--&gt; &lt;Property Name="SelectedIndex" Value=""/&gt; &lt;!--9--&gt; &lt;Property Name="Complete" Value=""/&gt; &lt;!--10--&gt; &lt;/Info&gt; &lt;/x:XData&gt; &lt;/XmlDataProvider&gt; </code></pre> <p>The ListView is defined as following:</p> <pre><code> &lt;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" &gt; &lt;ListView.View&gt; &lt;GridView AllowsColumnReorder="False"&gt; &lt;GridViewColumn CellTemplate="{StaticResource FirstCell}" Width="25" /&gt; &lt;GridViewColumn Header="Property" Width="80"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Label Style="{DynamicResource TsLabel}" Height="25" Width="115" Content="{Binding XPath=@Name}" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="Value" Width="130"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBox Style="{DynamicResource TsHelperTextBox}" Height="20" Width="115" Text="{Binding XPath=@Value}" IsEnabled="{Binding ElementName=rbTypeAssert, Path=IsChecked}" GotFocus="gridTextBox_GotFocus" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; </code></pre> <p>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:</p> <pre><code>lstProperties.ItemContainerGenerator.ContainerFromIndex(index) </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload