wpf tabControl切换前弹框确认

<Window x:Class="_temple.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1"
        Height="300"
        Width="300">
    <Grid>
        <TabControl TabItem.PreviewMouseLeftButtonUp="tabControl1_PreviewMouseLeftButtonUp"
                    Height="100"
                    Margin="28,76,50,86"
                    Name="tabControl1"
                    Width="200">
            <TabItem Header="tabItem1"
                     Name="tabItem1">
                <Grid />
            </TabItem>
            <TabItem Header="tabItem2"
                     Name="tabItem2">
                <Grid />
            </TabItem>

            <TabItem Header="tabItem3"
                     Name="tabItem3">
                <Grid />
            </TabItem>
        </TabControl>
    </Grid>
</Window> 

 

 

using System.Windows;
using System.Windows.Input;
namespace _temple
{
    /// <summary> 
    /// Interaction logic for Window1.xaml 
    /// </summary> 
    public partial class Window1 : Window
    {
        int selectindex = 0;
        public Window1()
        {
            InitializeComponent();
            tabControl1.SelectedIndex = 0;
            selectindex = 0;
        }
        private void tabControl1_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            MessageBoxResult msgResult = MessageBox.Show(
                "Would you like to proceed to the next section?",
                "Something",
                MessageBoxButton.YesNo,
                MessageBoxImage.Question);
            if (msgResult == MessageBoxResult.No)
            {
                e.Handled = true;
                tabControl1.SelectedIndex = selectindex;
            }
            else
            {
                selectindex = tabControl1.SelectedIndex;
                e.Handled = false;
            }
        }
    }
}

 

posted @ 2020-04-17 18:00  灰主流  阅读(929)  评论(0编辑  收藏  举报