如何处理 WPF 中的 TabItem 单击事件? [英] how to handle TabItem single click event in WPF?
本文介绍了如何处理 WPF 中的 TabItem 单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我使用了 WPF TabControl
我想处理 TabItem
的点击事件.我如何实现它?
In my application I have used WPF TabControl
I want to handle click event of the TabItem
.
How do i achieve it?
推荐答案
您可以通过向 tabcontrol 中每个 tabitem 的 header 属性添加标签来实现此目的.然后你可以为标签设置一个事件.
You can do this by adding labels to the header property for each tabitem in the tabcontrol. Then you can set an event for the label.
xml
<TabControl Height="100" HorizontalAlignment="Left" Name="tabControl1">
<TabItem Name="tabItem1">
<TabItem.Header>
<Label Content="tabItem1"
MouseLeftButtonDown="tabItem1_Clicked"
HorizontalAlignment="Stretch"/>
</TabItem.Header>
<Grid />
</TabItem>
<TabItem Name="tabItem2">
<TabItem.Header>
<Label Content="tabItem2"
MouseLeftButtonDown="tabItem2_Clicked"
HorizontalAlignment="Stretch"/>
</TabItem.Header>
<Grid />
</TabItem>
</TabControl>
C#/背后的代码
private void tabItem1_Clicked(object sender, MouseButtonEventArgs e)
{
//DO SOMETHING
}
private void tabItem2_Clicked(object sender, MouseButtonEventArgs e)
{
//DO SOMETHING
}
希望这会有所帮助.
这篇关于如何处理 WPF 中的 TabItem 单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文