[UWP] [VB]列表框文本选择不起作用 [英] [UWP][VB]list box text select not working

查看:72
本文介绍了[UWP] [VB]列表框文本选择不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是否是正确的位置,但我正在尝试开发一个在Windows手机上运行的应用程序。所以我有一个带有我的设计的xaml页面,到目前为止只是一个列表框,其中列表中的项目嵌入它不会从任何地方拉动数据
只是手动写入。我然后有一个文本块,以便当项目在列表框中时,它会显示但似乎无法正常工作。

hi not sure if this is the right location for this but i am trying to develop an app to run on windows phone. so i have an xaml page with my design on, so far just consists of a list box with the items on the list embedded its not pulling the data from anywhere just manually written in. i then have a text block so that when the item is in the list box it gets displayed but it doesnt seem to work.

这里首先编码xaml

here is coding xaml first

 < ListBox X:名称= QUOT;列表框"高度= QUOT; 67"余量= QUOT; 100,141,232,0" VerticalAlignment =" Top">

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < ListBox SelectionMode =" Single" SelectedValue =" selected_value1">< / ListBox>



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < ListBoxItem  Content =" T3100" />

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < ListBoxItem Content =" Z3200" />

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < ListBoxItem Content =" T2300" />

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < ListBoxItem Content =" T830" />

  &NBSP; &NBSP; &NBSP; < / ListBox>

 <ListBox x:Name="listBox" Height="67" Margin="100,141,232,0" VerticalAlignment="Top">
            <ListBox SelectionMode="Single" SelectedValue="selected_value1"></ListBox>

            <ListBoxItem  Content="T3100"/>
            <ListBoxItem Content="Z3200"/>
            <ListBoxItem Content="T2300"/>
            <ListBoxItem Content="T830"/>
        </ListBox>

visual basic section

visual basic section

  Private Sub selected_value1(sender As Object,e As SelectionChangedEventArgs)处理listBox.SelectionChanged



  &NBSP; &NBSP; &NBSP; result.Text = listBox.SelectedItem.ToString



$


  &NBSP;结束子

 Private Sub selected_value1(sender As Object, e As SelectionChangedEventArgs) Handles listBox.SelectionChanged

        result.Text = listBox.SelectedItem.ToString



    End Sub

它实际显示的是windows.ui.xaml.controls.listboxitem

what it actually displays is windows.ui.xaml.controls.listboxitem

不是我选择的文字???

not the text i have selected???

所有帮助赞赏

推荐答案

你好vindi93 ,

Hi vindi93,

我不确定我是否理解你的问题。如果您只想从ListBox中获取所选项目并将此项目的值显示为textblock,则使用SellectionChanged事件应该有效。

I’m not sure if I’ve understood your question. If you just want to get the selected item from ListBox and show this item’s value into textblock, then using SellectionChanged event should work.

请检查以下代码示例:

<ListBox x:Name="listBox" SelectionChanged="listBox_SelectionChanged">
            
            <ListBoxItem  Content="T3100"/>
            <ListBoxItem Content="Z3200"/>
            <ListBoxItem Content="T2300"/>
            <ListBoxItem Content="T830"/>
        </ListBox>
        <TextBlock x:Name="result" Margin="0 200 0 0" Height="50"></TextBlock>


private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBoxItem item = listBox.SelectedItem as ListBoxItem;
            if (item != null)
            {
                result.Text = item.Content as string;
            }
        }

最好的问候,

Xavier Eoro

Xavier Eoro


这篇关于[UWP] [VB]列表框文本选择不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆