AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.95k stars 2.25k forks source link

TabItem ZIndex not working #2610

Closed aguahombre closed 8 months ago

aguahombre commented 5 years ago

I have a problem similar to PR#369 in v0.8.0. I am trying to render the selected TabItem header on top of the tab content using a negative margin but with no success. I am using the styles

    <Style Selector="TabItem:selected">
      <Setter Property="Background" Value="LightCyan"/>
      <Setter Property="BorderBrush" Value="Black"/>
      <Setter Property="Margin" Value="0,0,0,-3"/>
      <Setter Property="BorderThickness" Value="1,1,1,0"/>
      <Setter Property="ZIndex" Value="200"/>
      <Setter Property="ClipToBounds" Value="False"/>
    </Style>
    <Style Selector="TabItem:selected:focus">
      <Setter Property="Background" Value="LightCyan"/>
      <Setter Property="BorderBrush" Value="Black"/>
      <Setter Property="Margin" Value="0,0,0,-3"/>
      <Setter Property="BorderThickness" Value="1,1,1,0"/>
      <Setter Property="ZIndex" Value="200"/>
      <Setter Property="ClipToBounds" Value="False"/>
    </Style>

with the tab control

    <TabControl Padding="0">
      <TabItem Header="A">
        <Border BorderBrush="Black" BorderThickness="0,1,0,0" Background="Transparent">
          <TextBlock Text="Text 1"/>
        </Border>
      </TabItem>
      <TabItem Header="B">
        <Border BorderBrush="Red" BorderThickness="0,1,0,0" Background="Transparent">
          <TextBlock Text="Text 2"/>
        </Border>
      </TabItem>
    </TabControl>

I get rendered image

I am not expecting to see the border line drawn over the selected tab item.

kekekeks commented 5 years ago

You also need to set ZIndex in TabControl's ItemPresenter: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Default/TabControl.xaml

aguahombre commented 5 years ago

I've tried that but with the same result

              <ItemsPresenter
                  Name="PART_ItemsPresenter"
                  Items="{TemplateBinding Items}"
                  ItemsPanel="{TemplateBinding ItemsPanel}"
                  ItemTemplate="{TemplateBinding ItemTemplate}"
                  ZIndex="300"
                  MemberSelector="{TemplateBinding MemberSelector}"                     >
              </ItemsPresenter>

and also ZIndex={TemplateBinding ZIndex}

kekekeks commented 5 years ago

@grokys

kekekeks commented 5 years ago

@Gillibald

mrj001 commented 3 years ago

I am having this problem in 0.10.0-rc1 with a Canvas as the parent, and Image children. This is modelled on how the BattleCity demo displays its sprites.

The ZIndex on the image is bound to control how images overlap with each other. Resizing the window does not affect how the children are drawn.