C# 在列表框内的itemtemplate中选择EdItem事件
我需要在listbox itemtemplate中更改选择事件。我的列表框由三个文本块和一个图像组成。我只想获取第三个文本块文本,当我选择第三个文本块时,文本块中的文本将显示为弹出窗口 我使用可视化树搜索textblock,但它采用第一个文本块的值,而不是第三个文本块的值。如何获取第二个和第三个文本块的值。我只需要在单击列表框中的文本块而不是整个列表框项时触发弹出窗口C# 在列表框内的itemtemplate中选择EdItem事件,c#,wpf,silverlight,windows-phone-7,xaml,C#,Wpf,Silverlight,Windows Phone 7,Xaml,我需要在listbox itemtemplate中更改选择事件。我的列表框由三个文本块和一个图像组成。我只想获取第三个文本块文本,当我选择第三个文本块时,文本块中的文本将显示为弹出窗口 我使用可视化树搜索textblock,但它采用第一个文本块的值,而不是第三个文本块的值。如何获取第二个和第三个文本块的值。我只需要在单击列表框中的文本块而不是整个列表框项时触发弹出窗口 <ListBox Name="listBox1" Width="Auto" SelectionChanged="Listb
<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>
使用TextBlock\u MouseLeftButtonUp或TextBlock\u轻触(当点击TextBlock时这是上升的) 在这方面,
private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TextBlock t = (TextBlock)sender;
string s= t.Text;
}
上面的字符串显示在您想要的位置。您可能应该将有问题的
文本块
包装在按钮中,或者向其添加超链接。两者都支持命令,并有一个单击事件。(要使按钮
不可见,您可以覆盖模板
,使其仅成为一个简单的内容演示者
)
<Button>
<Button.Template>
<ControlTemplate TargetType="Button"><ContentPresenter/></ControlTemplate>
</Button.Template>
<TextBlock .../>
</Button>
<TextBlock>
<!-- In SL you probably need a Run inside the Hyperlink and it may not be bindable -->
<Hyperlink Text="{Binding title}" .../>
</TextBlock>