-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add UI sample for Expander and bindings
- Loading branch information
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...s.Shared/Microsoft_UI_Xaml_Controls/ExpanderTests/Expander_Bindings_TemplatedControl.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
53 changes: 53 additions & 0 deletions
53
...hared/Microsoft_UI_Xaml_Controls/ExpanderTests/Expander_Bindings_TemplatedControl.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters