Skip to content

Commit 750a93e

Browse files
committed
fix + test app update
1 parent 3b98109 commit 750a93e

File tree

3 files changed

+109
-5
lines changed

3 files changed

+109
-5
lines changed

dev/TabView/TabViewItem.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ void TabViewItem::UpdateTabGeometry()
105105
{
106106
auto const templateSettings = winrt::get_self<TabViewItemTemplateSettings>(TabViewTemplateSettings());
107107

108-
// Need to increment actual height by 1 due to 'SelectedBackgroundPath' not being drawn correctly in non-100% scale factors
109-
auto const height = ActualHeight() + 1;
108+
auto const height = ActualHeight();
110109
auto const popupRadius = unbox_value<winrt::CornerRadius>(ResourceAccessor::ResourceLookup(*this, box_value(c_overlayCornerRadiusKey)));
111110
auto const leftCorner = popupRadius.TopLeft;
112111
auto const rightCorner = popupRadius.TopRight;
@@ -116,11 +115,11 @@ void TabViewItem::UpdateTabGeometry()
116115

117116
WCHAR strOut[1024];
118117
StringCchPrintf(strOut, ARRAYSIZE(strOut), data,
119-
height - 1,
118+
height,
120119
leftCorner, leftCorner, leftCorner, leftCorner, leftCorner,
121120
ActualWidth() - (leftCorner + rightCorner),
122121
rightCorner, rightCorner, rightCorner, rightCorner,
123-
height - (4 + rightCorner + 1));
122+
height - (4 + rightCorner));
124123

125124
const auto geometry = winrt::XamlReader::Load(strOut).try_as<winrt::Geometry>();
126125

dev/TabView/TestUI/TabViewPage.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1111
mc:Ignorable="d">
1212

13-
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
13+
<Grid x:Name="BackgroundGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
1414
<Grid>
1515
<Grid.ColumnDefinitions>
1616
<ColumnDefinition Width="Auto"/>
@@ -53,6 +53,11 @@
5353
<Button x:Name="ScrollTabViewToTheRight" AutomationProperties.Name="ScrollTabViewToTheRight" Content="Scroll TabView To the Right" Margin="0,0,0,8" Click="TabViewScrollToTheRightButton_Click" />
5454

5555
<Button x:Name="ShortLongTextButton" AutomationProperties.Name="ShortLongTextButton" Content="Short/Long Text" Margin="0,0,0,8" Click="ShortLongTextButton_Click" />
56+
<Button x:Name="HomeTabOverlapCheck" AutomationProperties.Name="HomeTabOverlapCheck" Content="Set HomeTabOverlapCheck" Margin="0,0,0,8" Click="HomeTabOverlapCheck_Click" />
57+
<Button x:Name="SetActiveTabTransparent" AutomationProperties.Name="SetActiveTabTransparent" Content="Set ActiveTab Transparent" Margin="0,0,0,8" Click="SetActiveTabTransparent_Click" />
58+
<Button x:Name="SetActiveContentTransparent" AutomationProperties.Name="SetActiveContentTransparent" Content="Set ActiveContent Transparent" Margin="0,0,0,8" Click="SetActiveContentTransparent_Click" />
59+
<Button x:Name="ClearOverlapCheck" AutomationProperties.Name="ClearOverlapCheck" Content="Clear OverlapCheck" Margin="0,0,0,8" Click="ClearOverlapCheck_Click" />
60+
5661
<StackPanel Orientation="Horizontal">
5762
<Button Click="SetColorsButton_Click" Content="Set Colors"/>
5863
<Button Click="ClearColorsButton_Click" Content="Clear Colors"/>

dev/TabView/TestUI/TabViewPage.xaml.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using Windows.UI;
1111
using System.Windows.Input;
1212
using Windows.UI.Xaml.Automation;
13+
using Windows.UI.Xaml.Shapes;
14+
using System.Reflection;
1315

1416
using TabView = Microsoft.UI.Xaml.Controls.TabView;
1517
using TabViewItem = Microsoft.UI.Xaml.Controls.TabViewItem;
@@ -55,8 +57,16 @@ public TabViewPage()
5557
itemSource.Add(item);
5658
}
5759
DataBindingTabView.TabItemsSource = itemSource;
60+
61+
backgroundColorCache = BackgroundGrid.Background;
62+
activeTabContentBackgroundBrushCache = FirstTabContent.Background;
63+
CacheFirstTabSelectedBackgroundPathFill();
5864
}
5965

66+
private Brush backgroundColorCache;
67+
private Brush activeTabSelectedBackgroundPathBrushCache;
68+
private Brush activeTabContentBackgroundBrushCache;
69+
6070
protected async override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs args)
6171
{
6272
NotCloseableTab.Visibility = Visibility.Collapsed;
@@ -409,6 +419,96 @@ private void ShortLongTextButton_Click(object sender, RoutedEventArgs e)
409419
FirstTab.Header = "s";
410420
LongHeaderTab.Header = "long long long long long long long long";
411421
}
422+
423+
private void HomeTabOverlapCheck_Click(object sender, RoutedEventArgs e)
424+
{
425+
var redBrush = new SolidColorBrush();
426+
redBrush.Color = Colors.Red;
427+
BackgroundGrid.Background = redBrush;
428+
429+
var tabBrush = new SolidColorBrush();
430+
tabBrush.Color = Colors.Blue;
431+
SetFirstTabSelectedBackgroundPathFill(tabBrush);
432+
433+
var contentBrush = new SolidColorBrush();
434+
contentBrush.Color = Colors.Green;
435+
FirstTabContent.Background = contentBrush;
436+
}
437+
438+
private void SetActiveTabTransparent_Click(object sender, RoutedEventArgs e)
439+
{
440+
var tabBrush = new SolidColorBrush();
441+
tabBrush.Color = Colors.Transparent;
442+
SetFirstTabSelectedBackgroundPathFill(tabBrush);
443+
}
444+
445+
private void SetActiveContentTransparent_Click(object sender, RoutedEventArgs e)
446+
{
447+
var contentBrush = new SolidColorBrush();
448+
contentBrush.Color = Colors.Transparent;
449+
FirstTabContent.Background = contentBrush;
450+
}
451+
452+
private void ClearOverlapCheck_Click(object sender, RoutedEventArgs e)
453+
{
454+
BackgroundGrid.Background = backgroundColorCache;
455+
456+
if(activeTabSelectedBackgroundPathBrushCache != null)
457+
{
458+
FrameworkElement selectedBackgroundPath = FindFrameworkElementWithName("SelectedBackgroundPath", FirstTab);
459+
if(selectedBackgroundPath != null)
460+
{
461+
(selectedBackgroundPath as Path).Fill = activeTabSelectedBackgroundPathBrushCache;
462+
}
463+
}
464+
465+
if(activeTabContentBackgroundBrushCache != null)
466+
{
467+
FirstTabContent.Background = activeTabContentBackgroundBrushCache;
468+
}
469+
}
470+
471+
private void CacheFirstTabSelectedBackgroundPathFill()
472+
{
473+
FrameworkElement selectedBackgroundPath = FindFrameworkElementWithName("SelectedBackgroundPath", FirstTab);
474+
if(selectedBackgroundPath != null)
475+
{
476+
activeTabSelectedBackgroundPathBrushCache = (selectedBackgroundPath as Path).Fill;
477+
}
478+
}
479+
480+
private void SetFirstTabSelectedBackgroundPathFill(Brush newBrush)
481+
{
482+
FrameworkElement selectedBackgroundPath = FindFrameworkElementWithName("SelectedBackgroundPath", FirstTab);
483+
if(selectedBackgroundPath != null)
484+
{
485+
(selectedBackgroundPath as Path).Fill = newBrush;
486+
}
487+
}
488+
489+
private FrameworkElement FindFrameworkElementWithName(string name, DependencyObject startNode)
490+
{
491+
int count = VisualTreeHelper.GetChildrenCount(startNode);
492+
for (int i = 0; i < count; i++)
493+
{
494+
DependencyObject current = VisualTreeHelper.GetChild(startNode, i);
495+
if ((current.GetType()).Equals(typeof(FrameworkElement)) || (current.GetType().GetTypeInfo().IsSubclassOf(typeof(FrameworkElement))))
496+
{
497+
FrameworkElement fe = (FrameworkElement)current;
498+
if(fe.Name == name)
499+
{
500+
return fe;
501+
}
502+
}
503+
var result = FindFrameworkElementWithName(name, current);
504+
if(result != null)
505+
{
506+
return result;
507+
}
508+
}
509+
return null;
510+
}
511+
412512
private void SetColorsButton_Click(object sender, RoutedEventArgs e)
413513
{
414514
var foregroundBrush = new SolidColorBrush();

0 commit comments

Comments
 (0)