Skip to content

Commit

Permalink
Fix 8743 - now using specific style in SearchBar [UWP] (#8773)
Browse files Browse the repository at this point in the history
* Adding a test page for Issue 8743.

* Correcting UITestCategory

* Renaming AutoSuggestStyle.xaml -> FormsAutoSuggestBoxStyle.xaml; adding x:Key to AutoSuggestBox-style.

* Applying style to AutoSuggestBox in SearchNarRenderer - fixing 8743

* Removing comment about default style - as style is no longer default

* Fixing typo in class name for Issue8743 (was erroneously Issue8843, might create conflict)

* Making GlyphElement in FormsCancelButton template use TemplateBinding for FontSize instead of fixed 12 pts.

* Updating nuspec to include FormsAutoSuggestBoxStyle instead of AutoSuggestStyle
fixes #8743
  • Loading branch information
WayaFlyfeather authored and samhouts committed Jan 9, 2020
1 parent de3ca13 commit 6fab987
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Linq;
using System.Threading.Tasks;


#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 8743, "[Bug][UWP] SearchBar does not respect FontSize on 4.3.0",
PlatformAffected.UWP)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.SearchBar)]
#endif
public class Issue8743 : TestContentPage
{
protected override void Init()
{
Title = "Issue 8743";

StackLayout layout = new StackLayout();

Label instructions = new Label
{
Text = "Check that the font size in the search bars below matches the size specified in the placeholders."
};

SearchBar normalSearchBar = new SearchBar
{
Placeholder = "FontSize = default"
};

SearchBar largeSearchBar = new SearchBar
{
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(SearchBar)),
Placeholder = "FontSize = Large"
};

SearchBar size100SearchBar = new SearchBar
{
FontSize = 100f,
Placeholder = "FontSize = 100.0"
};

layout.Children.Add(instructions);
layout.Children.Add(normalSearchBar);
layout.Children.Add(largeSearchBar);
layout.Children.Add(size100SearchBar);

Content = layout;
}
}
}
Expand Up @@ -127,6 +127,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue8741.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8743.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RefreshViewTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />
Expand Down
Expand Up @@ -3,8 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uwp="using:Xamarin.Forms.Platform.UWP">

<!-- Default Style for AutoSuggestBox -->
<Style TargetType="AutoSuggestBox">
<Style TargetType="AutoSuggestBox" x:Key="FormsAutoSuggestBoxStyle">
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TextBoxStyle" Value="{StaticResource AutoSuggestBoxFormsTextBoxStyle}" />
Expand Down Expand Up @@ -133,7 +132,7 @@
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontStyle="Normal"
FontSize="12"
FontSize="{TemplateBinding FontSize}"
Text="&#xE10A;"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
AutomationProperties.AccessibilityView="Raw"/>
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.UAP/Resources.xaml
Expand Up @@ -10,7 +10,7 @@
<ResourceDictionary Source="FormsProgressBarStyle.xaml" />
<ResourceDictionary Source="FormsTextBoxStyle.xaml" />
<ResourceDictionary Source="FormsCheckBoxStyle.xaml" />
<ResourceDictionary Source="AutoSuggestStyle.xaml" />
<ResourceDictionary Source="FormsAutoSuggestBoxStyle.xaml" />
<ResourceDictionary Source="MasterDetailControlStyle.xaml" />
<ResourceDictionary Source="TabbedPageStyle.xaml" />
<ResourceDictionary Source="SliderStyle.xaml" />
Expand Down
7 changes: 6 additions & 1 deletion Xamarin.Forms.Platform.UAP/SearchBarRenderer.cs
Expand Up @@ -29,7 +29,12 @@ protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
if (Control == null)
{
SetNativeControl(new AutoSuggestBox { QueryIcon = new SymbolIcon(Symbol.Find) });
AutoSuggestBox nativeAutoSuggestBox = new AutoSuggestBox
{
QueryIcon = new SymbolIcon(Symbol.Find),
Style = Windows.UI.Xaml.Application.Current.Resources["FormsAutoSuggestBoxStyle"] as Windows.UI.Xaml.Style
};
SetNativeControl(nativeAutoSuggestBox);
Control.QuerySubmitted += OnQuerySubmitted;
Control.TextChanged += OnTextChanged;
Control.Loaded += OnControlLoaded;
Expand Down
Expand Up @@ -30,7 +30,7 @@
</NoWarn>
</PropertyGroup>
<ItemGroup Condition=" '$(OS)' == 'Windows_NT' ">
<Page Include="AutoSuggestStyle.xaml">
<Page Include="FormsAutoSuggestBoxStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down

0 comments on commit 6fab987

Please sign in to comment.