C# 如何在WPF中将我的控件设置在其他控件之上

C# 如何在WPF中将我的控件设置在其他控件之上,c#,wpf,xaml,C#,Wpf,Xaml,我有一个选项卡控件,我在其中修改了模板。目标是在TabItems组的右侧和TabContent上方放置一个切换按钮。这很有效。当点击切换按钮时,我需要显示在切换按钮下方但位于选项卡内容上方的面板 我原以为我可以用ZIndex做到这一点,但到目前为止我一直没有成功。该窗口位于选项卡内容的后面或推出选项卡区域 <Style TargetType="{x:Type TabControl}"> <Setter Property="Template">

我有一个选项卡控件,我在其中修改了模板。目标是在TabItems组的右侧和TabContent上方放置一个切换按钮。这很有效。当点击切换按钮时,我需要显示在切换按钮下方但位于选项卡内容上方的面板

我原以为我可以用ZIndex做到这一点,但到目前为止我一直没有成功。该窗口位于选项卡内容的后面或推出选项卡区域

<Style  TargetType="{x:Type TabControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <StackPanel Orientation="Horizontal" Height="20">
                        <TabPanel Grid.Row="0" Panel.ZIndex="1"  Margin="0,0,4,-1"  IsItemsHost="True" Background="Transparent" />
                            <UniformGrid Columns="3" Rows="1" Height="20" Width="500" Margin="150,0,0,0">
                                <WrapPanel Height="20">
                                    <Label Content="Status" Margin="0,0,5,0" Padding="0,0,0,0" VerticalContentAlignment="Center" Height="Auto" />
                                    <ToggleButton Height="18" Padding="0,0,0,0">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Unchecked">
                                                <ei:ChangePropertyAction TargetName="StatusOverlay" PropertyName="Visibility" Value="Collapsed" />
                                            </i:EventTrigger>
                                            <i:EventTrigger EventName="Checked">
                                                <ei:ChangePropertyAction TargetName="StatusOverlay" PropertyName="Visibility" Value="Visible"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                        <WrapPanel Margin="0,0,0,0">
                                            <Path Style="{StaticResource StatusSuccess}" />
                                            <Path Style="{StaticResource StatusFailure}" />
                                            <Path Style="{StaticResource StatusSuccess}" />
                                        </WrapPanel> 
                                    </ToggleButton>
                                </WrapPanel>

                                <!-- Placeholder for another item-->
                                <WrapPanel Height="20"> 
                                </WrapPanel>

                                <!-- Placeholder for another item-->
                                <WrapPanel Height="20"> 
                                </WrapPanel> 
                            </UniformGrid> 
                        </StackPanel>

                        <!-- This would be the Panel I want to sit on top -->
                        <Border x:Name="StatusOverlay" Panel.ZIndex="99"  BorderBrush="Black" BorderThickness="3" HorizontalAlignment="Left" Height="403"  VerticalAlignment="Top" Width="325" Background="#FFD9D9D9" CornerRadius="6" Visibility="Collapsed">

                        </Border>
                        <Border Panel.ZIndex="1" Grid.Row="1" BorderBrush="Black"  BorderThickness="1" CornerRadius="0, 12, 12, 12" > 
                            <Border.Background>
                                <LinearGradientBrush>
                                    <GradientStop Color="LightBlue" Offset="0" />
                                    <GradientStop Color="White" Offset=".5" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <ContentPresenter ContentSource="SelectedContent" />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

看看这个答案:我只是猜测将ZIndex=99的边框移动到StackPanel之前。那就是边界了出于好奇,为什么要将所有这些都塞进TabControl的样式模板中,而不是仅仅制作一个UserControl,因为我认为它也可以在其他地方使用?@Chris W。你的意思是移动我试图隐藏和展示的状态面板,还是将tab控件全部丢弃?是的,将一些对象分离出来,而不是将它们放入其中一个的样式模板中。