列表框中项目模板中的 Selecteditem 事件
我需要在列表框项模板内更改选择事件。我的列表框由三个文本块和一个图像组成。我只想获取第三个文本块文本,当我选择第三个文本块时,文本块中的文本将显示为弹出窗口。
我使用可视化树来搜索文本块,但它采用第一个文本块的值而不是第三个文本块。我可以做什么来获取第二个和第三个文本块的值。仅当我单击列表框中的文本块而不是整个列表框项目时,我才需要触发弹出窗口。
<ListBox Name="listBox1" Width="Auto" SelectionChanged="Listbox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Height="165" HorizontalAlignment="Left" Margin="10,40,-400,0" VerticalAlignment="Top" Width="175" Source="{Binding thumb}"/>
<TextBlock Name="pagetext" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-135,-200,0" Text="{Binding page}" Foreground="#FF170101" />
<TextBlock Name="titletext" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" />
<TextBlock Name="text" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I need to have selection changed event inside a listbox itemtemplate. My listbox consists of three textblocks and an image. I want to get the third text block text only and when I select the third textblock the text in the text block will appear as a popup.
I used the visual tree to search for a textblock but it take the value of first text block instead of third textblock. What can i do to get the value of 2nd and 3rd textblocks. And I need to trigger a popup only when I click the textblock in the listbox not the whole listbox item.
<ListBox Name="listBox1" Width="Auto" SelectionChanged="Listbox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Height="165" HorizontalAlignment="Left" Margin="10,40,-400,0" VerticalAlignment="Top" Width="175" Source="{Binding thumb}"/>
<TextBlock Name="pagetext" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-135,-200,0" Text="{Binding page}" Foreground="#FF170101" />
<TextBlock Name="titletext" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" />
<TextBlock Name="text" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 TextBlock_MouseLeftButtonUp 或 TextBlock_Tap(这是单击文本块时上升)
在此,
上面的字符串显示在您想要的位置。
use TextBlock_MouseLeftButtonUp or TextBlock_Tap(this is rise when click on textblock)
In this,
the above string s disply where you want.
您可能应该将有问题的
TextBlock
包装在Button
中或向其添加Hyperlink
。两者都支持命令并具有Click
事件。 (要使Button
不可见,您可以将Template
重写为仅简单的ContentPresenter
)You should probably wrap the
TextBlock
in question in aButton
or add anHyperlink
to it. Both support commands and have aClick
event. (To make theButton
invisble you can override theTemplate
to be a simpleContentPresenter
only)