绑定ListboxItems我很新的WPF所以原谅我的任何愚蠢的问题...如何从ListView控件在WPF
我有被绑定到一个XmlDataProvider源,如以下三列一个ListView :
<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>
ListView控件定义如下:
<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 [email protected]}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Value" Width="130">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Style="{DynamicResource TsHelperTextBox}"
Height="20" Width="115" Text="{Binding [email protected]}"
IsEnabled="{Binding ElementName=rbTypeAssert, Path=IsChecked}" GotFocus="gridTextBox_GotFocus" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
我想现在做的是相当简单:我只是想启用/禁用某些ListViewItems的。 我找到致富ListViewItems的唯一方法是通过下面的方法:
lstProperties.ItemContainerGenerator.ContainerFromIndex(index)
这让我有点不舒服。我应该通过Property的名称属性获取项目。无论如何要做到这一点? 当我尝试在窗口初始化后立即执行此操作时,我也遇到问题。当试图禁用这些ListViewItems中的一个时,我得到一个NullReferenceException。看起来在窗口呈现之后,绑定还没有完成。
谢谢,我已经想到了什么像这样,但我用这种方法有三个问题 。 1.如何定义一个自定义属性(OK这真的是一个新手问题) 2.我已经有一个为我的应用程序中的所有ListViewItems定义的样式。你的解决方案是否意味着我必须为这些ListViewItems有特定的风格?最重要的是,3.在这种特殊情况下,我需要每个ListViewItem一个属性,而不是一个普通属性。我可以从XmlDataSource绑定这个吗? 谢谢 – jpsstavares 2010-02-22 20:49:23