我有一个带有listview的弹出窗口:
<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中的整数值
答案 0 :(得分:1)
您好将listViewResultados.SelectedItem
转换为您的ListView ItemsSource绑定到的收集项的类型。就像你的ItemsSource被绑定到字符串List一样,就像(string)listViewResultados.SelectedItem一样。我希望这会有所帮助。