Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Add Sample Test for Expander header bindings #17895

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<UserControl
x:Class="UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.Expander_Bindings_TemplatedControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<ResourceDictionary>
<Style BasedOn="{StaticResource DefaultSettingsExpanderStyle}"
TargetType="local:SettingsExpander" />

<Style x:Key="DefaultSettingsExpanderStyle"
TargetType="local:SettingsExpander">
<Style.Setters>
<Setter Property="Background" Value="{ThemeResource SettingsCardBackground}" />
<Setter Property="Foreground" Value="{ThemeResource SettingsCardForeground}" />
<Setter Property="BorderBrush" Value="{ThemeResource SettingsCardBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource SettingsCardBorderThickness}" />
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
<Setter Property="MinHeight" Value="{ThemeResource SettingsCardMinHeight}" />
<Setter Property="MinWidth" Value="{ThemeResource SettingsCardMinWidth}" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
<Setter Property="Padding" Value="{ThemeResource SettingsExpanderHeaderPadding}" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
<Setter Property="FocusVisualMargin" Value="-3" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:SettingsExpander">
<Expander MinWidth="{TemplateBinding MinWidth}"
x:Name="PART_Expander"
MinHeight="{TemplateBinding MinHeight}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
CornerRadius="{TemplateBinding CornerRadius}"
IsExpanded="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
<Expander.Header>
<Border Background="Purple">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding Header}"
Foreground="Red"
x:Name="PPT_TextBlock"
FontFamily="{TemplateBinding FontFamily}"
FontSize="28"/>
<TextBlock Text="On the Header"
Foreground="White"
Grid.Row="1"
FontFamily="{TemplateBinding FontFamily}"
FontSize="14"/>
</Grid>
</Border>
</Expander.Header>
<Expander.Content>
<Border Background="Gray">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding Header}"
Foreground="Red"
x:Name="PPT_TextBlock2"
FontFamily="{TemplateBinding FontFamily}"
FontSize="28"/>
<TextBlock Text="On the Content"
Foreground="White"
Grid.Row="1"
FontFamily="{TemplateBinding FontFamily}"
FontSize="14"/>
</Grid>
</Border>
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<local:SettingsExpander Header="Hello From Header in Custom Control"
IsExpanded="False"/>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#nullable enable
using Uno.UI.Samples.Controls;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml;
using Microsoft.Graph.Models;
using System;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests;

[Sample("Expander", "MUX", Name = "Expander_Bindings_TemplatedControl", isManualTest: true)]
public sealed partial class Expander_Bindings_TemplatedControl : UserControl
{
public Expander_Bindings_TemplatedControl()
{
this.InitializeComponent();
}
}

public partial class SettingsExpander : Control
{
public SettingsExpander() { }

public object Header
{
get => (object)GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}

public bool IsExpanded
{
get => (bool)GetValue(IsExpandedProperty);
set => SetValue(IsExpandedProperty, value);
}
protected virtual void OnIsExpandedPropertyChanged(bool oldValue, bool newValue)
{
}

public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
nameof(Header),
typeof(object),
typeof(SettingsExpander),
new PropertyMetadata(defaultValue: null));

public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(
nameof(IsExpanded),
typeof(bool),
typeof(SettingsExpander),
new PropertyMetadata(defaultValue: false, (d, e) => ((SettingsExpander)d).OnIsExpandedPropertyChanged((bool)e.OldValue, (bool)e.NewValue)));
}
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ExpanderTests\Expander_Bindings_TemplatedControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ImageIconTests\ImageIconPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -5461,6 +5465,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Helpers\UWPViewHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ViewModelBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\WaitableSampleImageHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ExpanderTests\Expander_Bindings_TemplatedControl.xaml.cs">
<DependentUpon>Expander_Bindings_TemplatedControl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\LoggingContentControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ItemsViewTests\Recipe.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lottie\LottieEmbeddedJson.xaml.cs">
Expand Down
Loading