1

我正在编写一个选项卡式应用程序,其中我使用了一个带有 4 个选项卡项的选项卡控件,我在选项卡 4 中有一个按钮,当我单击它时我想返回到第一个选项卡,我尝试了 TabControl.SelectedIndex = 0 但似乎它不工作,你能帮忙吗?

这是xaml

        <TabControl x:Name="TabAdd" HorizontalAlignment="Left" Height="535" VerticalAlignment="Top" Width="645" BorderBrush="#FFE8E8E8" Padding="0" IsSynchronizedWithCurrentItem="True" IsTextSearchEnabled="True">
            <TabItem x:Name="TabAddFlat" Header="Flat View" TabIndex="0"><!--IsSelected="True"-->
                <Grid Background="#FFFBFBFB" Margin="0">
                    <Grid x:Name="GridAddFlat" HorizontalAlignment="Left" Height="466" VerticalAlignment="Top" Width="407" Margin="109,10,0,0">
                        <Image HorizontalAlignment="Left" Height="466" VerticalAlignment="Top" Width="274" Source="Resources/F18.large - Copy.png" Margin="3,0,0,0"/>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem x:Name="TabAddSide" Header="Side View" TabIndex="1">
                <TabItem.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFF3F3F3" Offset="0"/>
                        <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                        <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                        <GradientStop Color="#FFFBFBFB" Offset="1"/>
                    </LinearGradientBrush>
                </TabItem.Background>
                <Grid Background="#FFFBFBFB">
                    <Grid x:Name="GridAddSide" HorizontalAlignment="Left" Height="345" VerticalAlignment="Top" Width="444" Margin="119,49,0,0">
                        <Image HorizontalAlignment="Left" Height="343" VerticalAlignment="Top" Width="394" Source="Resources/F1.large.png"/>                         
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem TabIndex="3" x:Name="TabAddInfo" Header="Customer Info" HorizontalAlignment="Left" Height="45" VerticalAlignment="Top" Width="184" Margin="0,0,-78,0">
                <TabItem.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFF3F3F3" Offset="0"/>
                        <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                        <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                        <GradientStop Color="#FFE8E8E8" Offset="1"/>
                    </LinearGradientBrush>
                </TabItem.Background>
                <Grid Background="#FFFBFBFB">
                    <Grid x:Name="GridAddInfo" HorizontalAlignment="Left" Height="466" VerticalAlignment="Top" Width="407" Margin="109,10,0,0">                           
                        <TextBox x:Name="iaddress" MaxHeight="288" Height="95" Width="288" Controls:TextboxHelper.ClearTextButton="True" Controls:TextboxHelper.Watermark="Address" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.IsSharedSizeScope="True" Padding="0" UseLayoutRounding="True" RenderTransformOrigin="0.5,0.5" Margin="27,246,92,125" AutoWordSelection="True" />

                    </Grid>
                </Grid>
            </TabItem>
            <TabItem TabIndex="3" x:Name="TabAddReview" Header="Review" HorizontalAlignment="Left" Height="45" VerticalAlignment="Top" Width="106" GotFocus="LoadAddReview">
                <TabItem.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFF3F3F3" Offset="0"/>
                        <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                        <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                        <GradientStop Color="#FFFBFBFB" Offset="1"/>
                    </LinearGradientBrush>
                </TabItem.Background>
                <Grid Background="#FFFBFBFB">
                    <Image HorizontalAlignment="Left" Height="32" Margin="15,15,0,0" VerticalAlignment="Top" Width="32" Source="Resources/save-64.png" MouseLeftButtonDown="SaveFormAll"/>                       
                    </Grid>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>

这是c#代码

    private void SaveFormAll(object sender, MouseButtonEventArgs e)
    {
        TabAdd.SelectedIndex = 2;
    }
4

1 回答 1

3

在您用作按钮的图像上,将 MouseLeftButtonDown="SaveFormAll" 更改为 MouseLeftButtonUp="SaveFormAll" 并重试。那应该行得通。

问题似乎是您的 MouseLeftButtonDown 处理程序正在触发,但 MouseLeftButtonUp 事件立即跟随它并将焦点放回图像上,这意味着最后一个选项卡保持活动状态。当我将其更改为使用 MouseLeftButtonUp 时,它起作用了。

于 2013-06-21T18:58:24.517 回答