microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

TabView. Shadow effect for selected tab in code behind. #6550

Open valvasiliev opened 2 years ago

valvasiliev commented 2 years ago

Describe the bug

I tried to create transparent tab style with TextBlock and Underline only. But, control always add shadow effect for selected tab. Looks like it is impossible to implement this style.

Steps to reproduce the bug

1)Try to create transparent tab. 2) You see Shadow and CornerRadius for selected tab.

Expected behavior

You able create transparent tab without any shadows and CornerRadius

Screenshots

Shadow

NuGet package version

WinUI 3 - Windows App SDK 1.0 (If you're seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

Device form factor

Desktop

Windows version

May 2021 Update (19043)

Additional context

Why you always add shadow effect in code behind? (looks like the same problem with corner radius for selected tab)

if (tabView)
    {
        if (SharedHelpers::IsThemeShadowAvailable())
        {
            if (internalTabView)
            {
                winrt::ThemeShadow shadow;
                if (!SharedHelpers::Is21H1OrHigher())
                {
                    if (auto shadowReceiver = internalTabView->GetShadowReceiver())
                    {
                        shadow.Receivers().Append(shadowReceiver);
                    }
                }
                m_shadow = shadow;

                double shadowDepth = unbox_value<double>(SharedHelpers::FindInApplicationResources(c_tabViewShadowDepthName, box_value(c_tabShadowDepth)));

                const auto currentTranslation = Translation();
                const auto translation = winrt::float3{ currentTranslation.x, currentTranslation.y, (float)shadowDepth };
                Translation(translation);

                UpdateShadow();
            }
        }
        m_tabDragStartingRevoker = tabView.TabDragStarting(winrt::auto_revoke, { this, &TabViewItem::OnTabDragStarting });
        m_tabDragCompletedRevoker = tabView.TabDragCompleted(winrt::auto_revoke, { this, &TabViewItem::OnTabDragCompleted });
    }

void TabViewItem::UpdateShadow()
{

    if (SharedHelpers::IsThemeShadowAvailable() && !XamlControlsResources::IsUsingControlsResourcesVersion2())
    {
        if (IsSelected() && !m_isDragging )
        {
            Shadow(m_shadow.as<winrt::ThemeShadow>());
        }
        else
        {
            Shadow(nullptr);
        }
    }
}
zadjii-msft commented 2 years ago

This also looks like #6076

StephenLPeters commented 2 years ago

There has been some work done on tabview in Winui2 and I think this issue will be resolved when we port that work to winui3 next.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

zadjii-msft commented 1 year ago

Actually, in retrospect, this is different from #6076. It's a bit like what we discussed in https://github.com/microsoft/terminal/issues/7213#issuecomment-1158020393. Because the TabViewItem sets this stuff in codebehind, it's literally impossible to remove certain styling.

(see also #7032)