我有一个弹出窗口,里面有一个列表视图:
<Popup Name="PopupResultados" Width="200" PlacementTarget="{Binding ElementName=textBoxBuscar}" AllowsTransparency="True" PopupAnimation="Slide">
<ListView Name="listViewResultados" Background="LightGray" BorderThickness="2" SelectionChanged="listViewResultados_SelectionChanged">
<ListView.View>
<GridView x:Name="gridViewResultados" ColumnHeaderContainerStyle="{StaticResource noHeader}">
<GridViewColumn Header="Col1" Width="0" DisplayMemberBinding="{Binding Col1}" />
<GridViewColumn Header="Col2" DisplayMemberBinding="{Binding Col2}" />
</GridView>
</ListView.View>
</ListView>
</Popup>
列表视图充满了字典:
private void buscar(object sender, RoutedEventArgs e)
{
Dictionary<int, String> dicc = admin.buscarEntidad(textBoxBuscar.Text);
if (!PopupResultados.IsOpen)
{
if (dicc.Count() != 0)
foreach (var par in dicc)
listViewResultados.Items.Add(new { Col1 = par.Key, Col2 = par.Value });
else
listViewResultados.Items.Add(new { Col2 = "No hay coincidencias" });
PopupResultados.IsOpen = true;
}
}
现在,我想在列表视图中选择一个项目并获取 Col1 中的整数值。
我怎样才能得到整数值?
当我输入时,我listViewResultados.SelectedItem.
只得到 4 种方法:Equals
、GetHashCode
和.GetType
ToString
忘了说我正在尝试获取 listViewResultados_SelectionChanged 中的整数值