这就是我将 2 文本块作为项目添加到我的列表框的方式
Dim StkP As New StackPanel
StkP.Name = "Stack"
Dim txtLine_1 As New TextBlock
txtLine_1.FontSize = 24
txtLine_1.Name = "txtLine_1"
txtLine_1.Text = "Units " + txtUnits_1.Text + ", Cost " + txtCost_1.Text
Dim txtLine_2 As New TextBlock
txtLine_2.FontSize = 24
txtLine_2.Name = "txtLine_2"
txtLine_2.Text = txtResult_1.Text
StkP.Children.Add(txtLine_1)
StkP.Children.Add(txtLine_2)
ListCompare.Items.Add(StkP)
但是,当我点击 vb.net 中的列表框时,如何检索所选项目的值?
我试过这段代码
Dim lbi As ListBoxItem = ListScore.ItemContainerGenerator.ContainerFromIndex(ListScore.SelectedIndex)
Dim stk As StackPanel = lbi.Content
Dim rs_1 As TextBlock = stk.FindName("lblScore_1")
Score_1.Text = rs_1.Text
但它总是返回“lblScore_1”的最后一个输入
任何帮助