我無法從列表視圖的子項列表框中獲取selecteditem。我試過的所有東西都會返回在父級列表視圖中設置的GpoObject,但不會從列表框中選擇所選的OuLink。如何獲取ListView中的SelectedItem和ListBox?
這是我爲ListBox的DataTemplate:
<DataTemplate x:Key="OuTemplate">
<Label Content="{Binding Path=Path}"/>
</DataTemplate>
這是我與它的列表框列表視圖:
<ListView x:Name="OutListView"
BorderBrush="#FFA0A0A0"
BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="Group Policy Objects"
Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Grid.Column="0"
Text="{Binding Path=Name}"
Width="Auto"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Organizational Units">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ListBox Grid.Column="1"
ItemsSource="{Binding Path=OUs}"
ItemTemplate="{DynamicResource OuTemplate}"
Width="Auto" Height="Auto"
BorderThickness="0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
對象綁定:
public class GpoObject
{
public string Name {get; set;}
public string Id { get; set; }
public List<OuLink> OUs { get; set; }
}
public class OuLink
{
public string Path { get; set; }
}
有人問類似的問題看看這裏http://stackoverflow.com/questions/28683297/how-to-access-properties-of-objects-supplied-to-event-handler-can-view-when-de/28683448#28683448,如果這沒有幫助請做一個谷歌搜索有噸工作示例在這裏'stackoverflow' – MethodMan 2015-02-23 21:46:41
你究竟在哪裏獲得選定的項目?取決於這個需求的*位置*可能會導致適當的答案。 – OmegaMan 2015-02-23 21:48:03
@OmegaMan我的計劃是允許用戶雙擊子列表框中的項目,並返回路徑。這是否回答你的問題? – 2015-02-24 12:59:53