2323using MUXControlsTestApp . Utilities ;
2424using System . Threading . Tasks ;
2525using Uno . UI . Samples . Controls ;
26- using System . Linq ;
26+ using UITests . Microsoft_UI_Xaml_Controls . TabViewTests ;
27+ using Microsoft . UI . Xaml . Shapes ;
28+ using System . Reflection ;
2729
28- namespace UITests . Microsoft_UI_Xaml_Controls . TabViewTests
30+ namespace MUXControlsTestApp
2931{
3032 public partial class TabDataItem : DependencyObject
3133 {
@@ -35,18 +37,20 @@ public partial class TabDataItem : DependencyObject
3537 }
3638
3739 [ Sample ( "TabView" , "MUX" ) ]
38- public sealed partial class TabViewPage : Page
40+ public sealed partial class TabViewPage : TestPage
3941 {
4042 int _newTabNumber = 1 ;
4143 SymbolIconSource _iconSource ;
4244
4345 public TabViewPage ( )
4446 {
4547 this . InitializeComponent ( ) ;
46- DisabledTab . Loaded += TabViewPage_Loaded ;
48+
4749 _iconSource = new SymbolIconSource ( ) ;
4850 _iconSource . Symbol = Symbol . Placeholder ;
4951
52+ Tabs . TabItemsChanged += Tabs_TabItemsChanged ;
53+
5054 ObservableCollection < TabDataItem > itemSource = new ObservableCollection < TabDataItem > ( ) ;
5155 for ( int i = 0 ; i < 5 ; i ++ )
5256 {
@@ -57,19 +61,22 @@ public TabViewPage()
5761 itemSource . Add ( item ) ;
5862 }
5963 DataBindingTabView . TabItemsSource = itemSource ;
60- }
6164
62- private void TabViewPage_Loaded ( object sender , RoutedEventArgs e )
63- {
64- var layoutRoot = ( Grid ) VisualTreeHelper . GetChild ( DisabledTab , 0 ) ;
65- VisualStateManager . GetVisualStateGroups ( layoutRoot ) . Single ( s => s . Name == "DisabledStates" ) . CurrentStateChanged += CurrentStateChanged ;
65+ backgroundColorCache = BackgroundGrid . Background ;
66+ activeTabContentBackgroundBrushCache = FirstTabContent . Background ;
67+ CacheFirstTabSelectedBackgroundPathFill ( ) ;
6668 }
6769
68- private void CurrentStateChanged ( object sender , VisualStateChangedEventArgs e )
70+ private void Tabs_TabItemsChanged ( TabView sender , Windows . Foundation . Collections . IVectorChangedEventArgs args )
6971 {
70- DisabledTabStateText . Text = "Disabled tab state: " + e . NewState . Name ;
72+ TabsItemChangedEventArgsTextBlock . Text = args . CollectionChange . ToString ( ) ;
73+ TabsItemChangedEventArgsIndexTextBlock . Text = args . Index . ToString ( ) ;
7174 }
7275
76+ private Brush backgroundColorCache ;
77+ private Brush activeTabSelectedBackgroundPathBrushCache ;
78+ private Brush activeTabContentBackgroundBrushCache ;
79+
7380 protected
7481#if HAS_UNO
7582 internal
@@ -300,9 +307,10 @@ private void OnTabStripDrop(object sender, Microsoft.UI.Xaml.DragEventArgs e)
300307 // This event is called when we're dragging between different TabViews
301308 // It is responsible for handling the drop of the item into the second TabView
302309
303- object obj ;
304- object objOriginTabView ;
305- if ( e . DataView . Properties . TryGetValue ( DataIdentifier , out obj ) && e . DataView . Properties . TryGetValue ( DataTabView , out objOriginTabView ) )
310+ object obj = null ;
311+ object objOriginTabView = null ;
312+ if ( e . DataView . Properties . TryGetValue ( DataIdentifier , out obj ) &&
313+ e . DataView . Properties . TryGetValue ( DataTabView , out objOriginTabView ) )
306314 {
307315 // TODO - BUG: obj should never be null, but occassionally is. Why?
308316 if ( obj == null || objOriginTabView == null )
@@ -355,13 +363,13 @@ private void OnTabStripDrop(object sender, Microsoft.UI.Xaml.DragEventArgs e)
355363 public void SetTabViewWidth_Click ( object sender , RoutedEventArgs e )
356364 {
357365 // This is the smallest width that fits our content without any scrolling.
358- Tabs . Width = 740 ;
366+ Tabs . Width = 752 ;
359367 }
360368
361369 public void GetScrollButtonsVisible_Click ( object sender , RoutedEventArgs e )
362370 {
363- var scrollDecrease = VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollDecreaseButton " ) as FrameworkElement ;
364- var scrollIncrease = VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollIncreaseButton " ) as FrameworkElement ;
371+ var scrollDecrease = VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollDecreaseButtonContainer " ) as FrameworkElement ;
372+ var scrollIncrease = VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollIncreaseButtonContainer " ) as FrameworkElement ;
365373 if ( scrollDecrease . Visibility == Visibility . Visible && scrollIncrease . Visibility == Visibility . Visible )
366374 {
367375 ScrollButtonsVisible . Text = "True" ;
@@ -408,17 +416,17 @@ public void GetScrollIncreaseButtonEnabled_Click(object sender, RoutedEventArgs
408416
409417 private void TabViewSizingPageButton_Click ( object sender , RoutedEventArgs e )
410418 {
411- this . GetFrame ( ) . Navigate ( typeof ( TabViewSizingPage ) ) ;
419+ this . Frame . Navigate ( typeof ( TabViewSizingPage ) ) ;
412420 }
413421
414422 private void TabViewTabClosingBehaviorButton_Click ( object sender , RoutedEventArgs e )
415423 {
416- this . GetFrame ( ) . Navigate ( typeof ( TabViewTabClosingBehaviorPage ) ) ;
424+ this . Frame . Navigate ( typeof ( TabViewTabClosingBehaviorPage ) ) ;
417425 }
418426
419427 private void TabViewTabItemsSourcePageButton_Click ( object sender , RoutedEventArgs e )
420428 {
421- this . GetFrame ( ) . Navigate ( typeof ( TabViewTabItemsSourcePage ) ) ;
429+ this . Frame . Navigate ( typeof ( TabViewTabItemsSourcePage ) ) ;
422430 }
423431
424432 private void ShortLongTextButton_Click ( object sender , RoutedEventArgs e )
@@ -427,64 +435,125 @@ private void ShortLongTextButton_Click(object sender, RoutedEventArgs e)
427435 LongHeaderTab . Header = "long long long long long long long long" ;
428436 }
429437
430- private void GetScrollDecreaseButtonToolTipButton_Click ( object sender , RoutedEventArgs e )
438+ private void HomeTabOverlapCheck_Click ( object sender , RoutedEventArgs e )
431439 {
432- if ( VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollDecreaseButton" ) is RepeatButton scrollDecreaseButton )
433- {
434- GetToolTipStringForUIElement ( scrollDecreaseButton , ScrollDecreaseButtonToolTipTextBlock ) ;
435- }
440+ var redBrush = new SolidColorBrush ( ) ;
441+ redBrush . Color = Colors . Red ;
442+ BackgroundGrid . Background = redBrush ;
443+
444+ var tabBrush = new SolidColorBrush ( ) ;
445+ tabBrush . Color = Colors . Blue ;
446+ SetFirstTabSelectedBackgroundPathFill ( tabBrush ) ;
447+
448+ var contentBrush = new SolidColorBrush ( ) ;
449+ contentBrush . Color = Colors . Green ;
450+ FirstTabContent . Background = contentBrush ;
436451 }
437452
438- private void GetScrollIncreaseButtonToolTipButton_Click ( object sender , RoutedEventArgs e )
453+ private void SetActiveTabTransparent_Click ( object sender , RoutedEventArgs e )
439454 {
440- if ( VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollIncreaseButton" ) is RepeatButton scrollIncreaseButton )
455+ var tabBrush = new SolidColorBrush ( ) ;
456+ tabBrush . Color = Colors . Transparent ;
457+ SetFirstTabSelectedBackgroundPathFill ( tabBrush ) ;
458+ }
459+
460+ private void SetActiveContentTransparent_Click ( object sender , RoutedEventArgs e )
461+ {
462+ var contentBrush = new SolidColorBrush ( ) ;
463+ contentBrush . Color = Colors . Transparent ;
464+ FirstTabContent . Background = contentBrush ;
465+ }
466+
467+ private void ClearOverlapCheck_Click ( object sender , RoutedEventArgs e )
468+ {
469+ BackgroundGrid . Background = backgroundColorCache ;
470+
471+ if ( activeTabSelectedBackgroundPathBrushCache != null )
441472 {
442- GetToolTipStringForUIElement ( scrollIncreaseButton , ScrollIncreaseButtonToolTipTextBlock ) ;
473+ FrameworkElement selectedBackgroundPath = FindFrameworkElementWithName ( "SelectedBackgroundPath" , FirstTab ) ;
474+ if ( selectedBackgroundPath != null )
475+ {
476+ ( selectedBackgroundPath as Path ) . Fill = activeTabSelectedBackgroundPathBrushCache ;
477+ }
478+ }
479+
480+ if ( activeTabContentBackgroundBrushCache != null )
481+ {
482+ FirstTabContent . Background = activeTabContentBackgroundBrushCache ;
443483 }
444484 }
445485
446- private void GetSecondTabHeaderForegroundButton_Click ( object sender , RoutedEventArgs e )
486+ private void CacheFirstTabSelectedBackgroundPathFill ( )
447487 {
448- if ( FindVisualChildByName ( SecondTab , "ContentPresenter" ) is ContentPresenter presenter
449- && presenter . Foreground is SolidColorBrush brush )
488+ FrameworkElement selectedBackgroundPath = FindFrameworkElementWithName ( "SelectedBackgroundPath" , FirstTab ) ;
489+ if ( selectedBackgroundPath != null )
450490 {
451- SecondTabHeaderForegroundTextBlock . Text = brush . Color . ToString ( ) ;
491+ activeTabSelectedBackgroundPathBrushCache = ( selectedBackgroundPath as Path ) . Fill ;
452492 }
453493 }
454494
455- //TODO: Move to MUX test page base when TreeView PR is merged
456- public static DependencyObject FindVisualChildByName ( FrameworkElement parent , string name )
495+ private void SetFirstTabSelectedBackgroundPathFill ( Brush newBrush )
457496 {
458- if ( parent . Name == name )
497+ FrameworkElement selectedBackgroundPath = FindFrameworkElementWithName ( "SelectedBackgroundPath" , FirstTab ) ;
498+ if ( selectedBackgroundPath != null )
459499 {
460- return parent ;
500+ ( selectedBackgroundPath as Path ) . Fill = newBrush ;
461501 }
502+ }
462503
463- int childrenCount = VisualTreeHelper . GetChildrenCount ( parent ) ;
464-
465- for ( int i = 0 ; i < childrenCount ; i ++ )
504+ private FrameworkElement FindFrameworkElementWithName ( string name , DependencyObject startNode )
505+ {
506+ int count = VisualTreeHelper . GetChildrenCount ( startNode ) ;
507+ for ( int i = 0 ; i < count ; i ++ )
466508 {
467- FrameworkElement childAsFE = VisualTreeHelper . GetChild ( parent , i ) as FrameworkElement ;
468-
469- if ( childAsFE != null )
509+ DependencyObject current = VisualTreeHelper . GetChild ( startNode , i ) ;
510+ if ( ( current . GetType ( ) ) . Equals ( typeof ( FrameworkElement ) ) || ( current . GetType ( ) . GetTypeInfo ( ) . IsSubclassOf ( typeof ( FrameworkElement ) ) ) )
470511 {
471- DependencyObject result = FindVisualChildByName ( childAsFE , name ) ;
472-
473- if ( result != null )
512+ FrameworkElement fe = ( FrameworkElement ) current ;
513+ if ( fe . Name == name )
474514 {
475- return result ;
515+ return fe ;
476516 }
477517 }
518+ var result = FindFrameworkElementWithName ( name , current ) ;
519+ if ( result != null )
520+ {
521+ return result ;
522+ }
478523 }
479-
480524 return null ;
481525 }
482526
483- // Uno Specific sample subpage navigation
484- private Frame GetFrame ( )
527+ private void SetColorsButton_Click ( object sender , RoutedEventArgs e )
528+ {
529+ var foregroundBrush = new SolidColorBrush ( ) ;
530+ foregroundBrush . Color = Colors . Blue ;
531+ SecondTab . Foreground = foregroundBrush ;
532+ var backgroundBrush = new SolidColorBrush ( ) ;
533+ backgroundBrush . Color = Colors . Purple ;
534+ SecondTab . Background = backgroundBrush ;
535+ }
536+
537+ private void ClearColorsButton_Click ( object sender , RoutedEventArgs e )
485538 {
486- NavFrameGrid . Visibility = Visibility . Visible ;
487- return NavFrame ;
539+ SecondTab . ClearValue ( ForegroundProperty ) ;
540+ SecondTab . ClearValue ( BackgroundProperty ) ;
541+ }
542+
543+ private void GetScrollDecreaseButtonToolTipButton_Click ( object sender , RoutedEventArgs e )
544+ {
545+ if ( VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollDecreaseButton" ) is RepeatButton scrollDecreaseButton )
546+ {
547+ GetToolTipStringForUIElement ( scrollDecreaseButton , ScrollDecreaseButtonToolTipTextBlock ) ;
548+ }
549+ }
550+
551+ private void GetScrollIncreaseButtonToolTipButton_Click ( object sender , RoutedEventArgs e )
552+ {
553+ if ( VisualTreeUtils . FindVisualChildByName ( Tabs , "ScrollIncreaseButton" ) is RepeatButton scrollIncreaseButton )
554+ {
555+ GetToolTipStringForUIElement ( scrollIncreaseButton , ScrollIncreaseButtonToolTipTextBlock ) ;
556+ }
488557 }
489558 }
490559}
0 commit comments