diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-08-16 12:10:32 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-08-16 11:10:32 -0700 |
commit | 30c0dcb949186c21c60c4c9ddf8a581d40a43662 (patch) | |
tree | 17a196012b9d4044f78cc0acbe9aa137d10f2b25 | |
parent | 966683a807f68f302e8f121279387109f2a4a73b (diff) | |
download | xamarin-forms-30c0dcb949186c21c60c4c9ddf8a581d40a43662.tar.gz xamarin-forms-30c0dcb949186c21c60c4c9ddf8a581d40a43662.tar.bz2 xamarin-forms-30c0dcb949186c21c60c4c9ddf8a581d40a43662.zip |
Fix Entry/SearchBar color issues (#306)
* Fix disappearing Entry text on UWP Anniversary Edition
Fix background color reversion bug in UWP Phone
Move SearchBar styling on UWP to its own file
Make foreground/background color changes on UWP SearchBar/Entry consistent
Fix SearchBar color toggle bug on WP8
* Temporarily moving SDK target to previous version
* Fix build error on OSX
16 files changed, 544 insertions, 532 deletions
diff --git a/.nuspec/Xamarin.Forms.nuspec b/.nuspec/Xamarin.Forms.nuspec index f57e53ad..16520f0f 100644 --- a/.nuspec/Xamarin.Forms.nuspec +++ b/.nuspec/Xamarin.Forms.nuspec @@ -239,6 +239,7 @@ <file src="..\Xamarin.Forms.Platform.UAP\bin\$Configuration$\PageControl.xbf" target="lib\uap10.0\Xamarin.Forms.Platform.UAP" /> <file src="..\Xamarin.Forms.Platform.UAP\bin\$Configuration$\Resources.xbf" target="lib\uap10.0\Xamarin.Forms.Platform.UAP" /> <file src="..\Xamarin.Forms.Platform.UAP\bin\$Configuration$\FormsTextBoxStyle.xbf" target="lib\uap10.0\Xamarin.Forms.Platform.UAP" /> + <file src="..\Xamarin.Forms.Platform.UAP\bin\$Configuration$\AutoSuggestStyle.xbf" target="lib\uap10.0\Xamarin.Forms.Platform.UAP" /> <file src="..\Xamarin.Forms.Core\bin\$Configuration$\Xamarin.Forms.Core.dll" target="lib\uap10.0" /> <file src="..\docs\Xamarin.Forms.Core.xml" target="lib\uap10.0" /> diff --git a/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj b/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj index a4952000..58ad67b3 100644 --- a/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj +++ b/Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj @@ -12,7 +12,7 @@ <AssemblyName>Xamarin.Forms.ControlGallery.WindowsUniversal</AssemblyName> <DefaultLanguage>en-US</DefaultLanguage> <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> - <TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion> + <TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion> <TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion> <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> <EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile> diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/DefaultColorToggleTest.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/DefaultColorToggleTest.cs index 4cd6cf5f..f943f158 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/DefaultColorToggleTest.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/DefaultColorToggleTest.cs @@ -58,7 +58,7 @@ namespace Xamarin.Forms.Controls static ContentPage SearchBarPage() { - var searchbarTextColorDefaultToggle = new Entry() { Text = "Default SearchBar Text Color" }; + var searchbarTextColorDefaultToggle = new SearchBar() { Text = "Default SearchBar Text Color" }; var searchbarTextColorToggleButton = new Button() { Text = "Toggle SearchBar Color" }; searchbarTextColorToggleButton.Clicked += (sender, args) => { if (searchbarTextColorDefaultToggle.TextColor.IsDefault) @@ -73,7 +73,7 @@ namespace Xamarin.Forms.Controls } }; - var searchbarPlaceholderColorDefaultToggle = new Entry() { Placeholder = "Default Placeholder Color" }; + var searchbarPlaceholderColorDefaultToggle = new SearchBar() { Placeholder = "Default Placeholder Color" }; var searchbarPlaceholderToggleButton = new Button() { Text = "Toggle Placeholder Color" }; searchbarPlaceholderToggleButton.Clicked += (sender, args) => { if (searchbarPlaceholderColorDefaultToggle.PlaceholderColor.IsDefault) diff --git a/Xamarin.Forms.Platform.UAP/AutoSuggestStyle.xaml b/Xamarin.Forms.Platform.UAP/AutoSuggestStyle.xaml new file mode 100644 index 00000000..3c85a01f --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/AutoSuggestStyle.xaml @@ -0,0 +1,389 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:uwp="using:Xamarin.Forms.Platform.UWP"> + + <!-- Default Style for AutoSuggestBox --> + <Style TargetType="AutoSuggestBox"> + <Setter Property="VerticalAlignment" Value="Top" /> + <Setter Property="IsTabStop" Value="False" /> + <Setter Property="TextBoxStyle" Value="{StaticResource AutoSuggestBoxTextBoxStyle}" /> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="AutoSuggestBox"> + <Grid> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="Orientation"> + <VisualState x:Name="Landscape"/> + <VisualState x:Name="Portrait"/> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <uwp:FormsTextBox x:Name="TextBox" + Style="{TemplateBinding TextBoxStyle}" + FontFamily="{TemplateBinding FontFamily}" + FontSize="{TemplateBinding FontSize}" + FontStyle="{TemplateBinding FontStyle}" + PlaceholderText="{TemplateBinding PlaceholderText}" + Header="{TemplateBinding Header}" + Width="{TemplateBinding Width}" + ScrollViewer.BringIntoViewOnFocusChange="False" + Canvas.ZIndex="0" + Margin="0" + DesiredCandidateWindowAlignment="BottomEdge"/> + <Popup x:Name="SuggestionsPopup"> + <Border x:Name="SuggestionsContainer"> + <Border.RenderTransform> + <TranslateTransform x:Name="UpwardTransform"/> + </Border.RenderTransform> + <ListView x:Name="SuggestionsList" + Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}" + BorderThickness="{ThemeResource AutoSuggestListBorderThemeThickness}" + BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" + DisplayMemberPath="{TemplateBinding DisplayMemberPath}" + IsItemClickEnabled="True" + ItemTemplate="{TemplateBinding ItemTemplate}" + ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}" + ItemContainerStyle="{TemplateBinding ItemContainerStyle}" + MaxHeight="{ThemeResource AutoSuggestListMaxHeight}" + Margin="{ThemeResource AutoSuggestListMargin}"> + <ListView.ItemContainerTransitions> + <TransitionCollection /> + </ListView.ItemContainerTransitions> + </ListView> + </Border> + </Popup> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="uwp:FormsTextBox" x:Key="AutoSuggestBoxTextBoxStyle"> + <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" /> + <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" /> + <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" /> + <Setter Property="ForegroundFocusBrush" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" /> + <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" /> + <Setter Property="PlaceholderForegroundFocusBrush" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" /> + <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" /> + <Setter Property="BackgroundFocusBrush" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" /> + <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" /> + <Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> + <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" /> + <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> + <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> + <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" /> + <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" /> + <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" /> + <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="uwp:FormsTextBox"> + <Grid> + <Grid.Resources> + <Style x:Name="DeleteButtonStyle" TargetType="Button"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="Button"> + <Grid> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal" /> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource FormsCancelBackgroundBrush}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <DoubleAnimation Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Opacity" + To="0" + Duration="0" /> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Border x:Name="BorderElement" + BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}" + BorderThickness="{TemplateBinding BorderThickness}" + Background="{ThemeResource FormsCancelBackgroundBrush}"> + <TextBlock x:Name="GlyphElement" + Foreground="{ThemeResource FormsCancelForegroundBrush}" + VerticalAlignment="Center" + HorizontalAlignment="Center" + FontStyle="Normal" + FontSize="12" + Text="" + FontFamily="{ThemeResource SymbolThemeFontFamily}" + AutomationProperties.AccessibilityView="Raw"/> + </Border> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + <Style x:Name="QueryButtonStyle" TargetType="Button"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="Button"> + <Grid> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal" /> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAccentBrush}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <DoubleAnimation Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Opacity" + To="0" + Duration="0" /> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Border x:Name="BorderElement" + BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}" + BorderThickness="{TemplateBinding BorderThickness}" + Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}"> + <ContentPresenter x:Name="ContentPresenter" + Content="{TemplateBinding Content}" + ContentTransitions="{TemplateBinding ContentTransitions}" + ContentTemplate="{TemplateBinding ContentTemplate}" + Margin="{TemplateBinding Padding}" + HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" + VerticalAlignment="{TemplateBinding VerticalContentAlignment}" + AutomationProperties.AccessibilityView="Raw"/> + </Border> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Grid.Resources> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="BorderBrush"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Normal" /> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="BorderBrush"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightChromeAltLowBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" + Storyboard.TargetProperty="Opacity"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Focused"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" + Storyboard.TargetProperty="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding BackgroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" + Storyboard.TargetProperty="Opacity"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocusedOpacity}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" + Storyboard.TargetProperty="BorderBrush"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding ForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" + Storyboard.TargetProperty="RequestedTheme"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Light" /> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="QueryButton" + Storyboard.TargetProperty="Foreground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundChromeBlackMediumBrush}" /> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="ButtonStates"> + <VisualState x:Name="ButtonVisible"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" + Storyboard.TargetProperty="Visibility"> + <DiscreteObjectKeyFrame KeyTime="0"> + <DiscreteObjectKeyFrame.Value> + <Visibility>Visible</Visibility> + </DiscreteObjectKeyFrame.Value> + </DiscreteObjectKeyFrame> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="ButtonCollapsed" /> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + <Border x:Name="BackgroundElement" + Grid.Row="1" + Background="{TemplateBinding Background}" + Margin="{TemplateBinding BorderThickness}" + Opacity="{ThemeResource TextControlBackgroundRestOpacity}" + Grid.ColumnSpan="3" + Grid.RowSpan="1"/> + <Border x:Name="BorderElement" + Grid.Row="1" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}" + Grid.ColumnSpan="3" + Grid.RowSpan="1"/> + <ContentPresenter x:Name="HeaderContentPresenter" + x:DeferLoadStrategy="Lazy" + Visibility="Collapsed" + Grid.Row="0" + Foreground="{Binding PlaceholderForegroundBrush, RelativeSource={RelativeSource TemplatedParent}}" + Margin="0,0,0,8" + Grid.ColumnSpan="3" + Content="{TemplateBinding Header}" + ContentTemplate="{TemplateBinding HeaderTemplate}" + FontWeight="Normal" + TextWrapping="Wrap" /> + <ScrollViewer x:Name="ContentElement" + Grid.Row="1" + HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" + HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" + VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" + VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" + IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" + IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" + IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" + Margin="{TemplateBinding BorderThickness}" + Padding="{TemplateBinding Padding}" + IsTabStop="False" + AutomationProperties.AccessibilityView="Raw" + ZoomMode="Disabled" /> + <!-- Converting the TextAlignment set for the control's input text to a HorizontalAlignment + so the PlaceholderText's alignment will match the input text --> + <ContentControl x:Name="PlaceholderTextContentPresenter" + Grid.Row="1" + Foreground="{Binding PlaceholderForegroundBrush, RelativeSource={RelativeSource TemplatedParent}}" + Margin="{TemplateBinding BorderThickness}" + Padding="{TemplateBinding Padding}" + IsTabStop="False" + Grid.ColumnSpan="3" + Content="{TemplateBinding PlaceholderText}" + FontFamily="{TemplateBinding FontFamily}" + FontSize="{TemplateBinding FontSize}" + FontStyle="{TemplateBinding FontStyle}" + IsHitTestVisible="False" + HorizontalAlignment="{Binding TextAlignment, + RelativeSource={RelativeSource Mode=TemplatedParent}, + Converter={StaticResource AlignmentConverter}}" /> + <Button x:Name="DeleteButton" + Grid.Row="1" + Style="{StaticResource DeleteButtonStyle}" + BorderThickness="{TemplateBinding BorderThickness}" + Margin="{ThemeResource HelperButtonThemePadding}" + IsTabStop="False" + Grid.Column="1" + Visibility="Collapsed" + FontSize="{TemplateBinding FontSize}" + MinWidth="34" + VerticalAlignment="Stretch"/> + <Button x:Name="QueryButton" + Grid.Row="1" + Style="{StaticResource QueryButtonStyle}" + BorderThickness="{TemplateBinding BorderThickness}" + Margin="{ThemeResource HelperButtonThemePadding}" + IsTabStop="False" + Grid.Column="2" + FontSize="{TemplateBinding FontSize}" + MinWidth="34" + VerticalAlignment="Stretch"/> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml index c573552a..f449ad5b 100644 --- a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml +++ b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml @@ -8,6 +8,9 @@ <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" /> <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" /> <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" /> + <Setter Property="ForegroundFocusBrush" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" /> + <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" /> + <Setter Property="PlaceholderForegroundFocusBrush" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" /> <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" /> <Setter Property="BackgroundFocusBrush" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" /> <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" /> @@ -15,7 +18,6 @@ <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" /> <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> - <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" /> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" /> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" /> <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" /> @@ -123,7 +125,7 @@ <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" /> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement"> @@ -137,7 +139,7 @@ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" /> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding ForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="RequestedTheme" Storyboard.TargetName="ContentElement"> diff --git a/Xamarin.Forms.Platform.UAP/Resources.xaml b/Xamarin.Forms.Platform.UAP/Resources.xaml index 5df785f0..5f3a4999 100644 --- a/Xamarin.Forms.Platform.UAP/Resources.xaml +++ b/Xamarin.Forms.Platform.UAP/Resources.xaml @@ -6,6 +6,7 @@ <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="FormsTextBoxStyle.xaml" /> + <ResourceDictionary Source="AutoSuggestStyle.xaml" /> </ResourceDictionary.MergedDictionaries> <uwp:CaseConverter x:Key="LowerConverter" ConvertToUpper="False" /> @@ -708,386 +709,5 @@ <SolidColorBrush x:Key="FormsCancelForegroundBrush" /> <SolidColorBrush x:Key="FormsCancelBackgroundBrush" /> - - <!-- Default Style for AutoSuggestBox --> - <Style TargetType="AutoSuggestBox"> - <Setter Property="VerticalAlignment" Value="Top" /> - <Setter Property="IsTabStop" Value="False" /> - <Setter Property="TextBoxStyle" Value="{StaticResource AutoSuggestBoxTextBoxStyle}" /> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="AutoSuggestBox"> - <Grid> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="Orientation"> - <VisualState x:Name="Landscape"/> - <VisualState x:Name="Portrait"/> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <uwp:FormsTextBox x:Name="TextBox" - Style="{TemplateBinding TextBoxStyle}" - FontFamily="{TemplateBinding FontFamily}" - FontSize="{TemplateBinding FontSize}" - FontStyle="{TemplateBinding FontStyle}" - PlaceholderText="{TemplateBinding PlaceholderText}" - Header="{TemplateBinding Header}" - Width="{TemplateBinding Width}" - ScrollViewer.BringIntoViewOnFocusChange="False" - Canvas.ZIndex="0" - Margin="0" - DesiredCandidateWindowAlignment="BottomEdge"/> - <Popup x:Name="SuggestionsPopup"> - <Border x:Name="SuggestionsContainer"> - <Border.RenderTransform> - <TranslateTransform x:Name="UpwardTransform"/> - </Border.RenderTransform> - <ListView x:Name="SuggestionsList" - Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}" - BorderThickness="{ThemeResource AutoSuggestListBorderThemeThickness}" - BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}" - DisplayMemberPath="{TemplateBinding DisplayMemberPath}" - IsItemClickEnabled="True" - ItemTemplate="{TemplateBinding ItemTemplate}" - ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}" - ItemContainerStyle="{TemplateBinding ItemContainerStyle}" - MaxHeight="{ThemeResource AutoSuggestListMaxHeight}" - Margin="{ThemeResource AutoSuggestListMargin}"> - <ListView.ItemContainerTransitions> - <TransitionCollection /> - </ListView.ItemContainerTransitions> - </ListView> - </Border> - </Popup> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> - - <Style TargetType="uwp:FormsTextBox" x:Key="AutoSuggestBoxTextBoxStyle"> - <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" /> - <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" /> - <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" /> - <Setter Property="ForegroundFocusBrush" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" /> - <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" /> - <Setter Property="PlaceholderForegroundFocusBrush" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" /> - <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" /> - <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" /> - <Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> - <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" /> - <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> - <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> - <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" /> - <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" /> - <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" /> - <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="uwp:FormsTextBox"> - <Grid> - <Grid.Resources> - <Style x:Name="DeleteButtonStyle" TargetType="Button"> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="Button"> - <Grid> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="CommonStates"> - <VisualState x:Name="Normal" /> - <VisualState x:Name="PointerOver"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource FormsCancelBackgroundBrush}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Pressed"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Disabled"> - <Storyboard> - <DoubleAnimation Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Opacity" - To="0" - Duration="0" /> - </Storyboard> - </VisualState> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <Border x:Name="BorderElement" - BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}" - BorderThickness="{TemplateBinding BorderThickness}" - Background="{ThemeResource FormsCancelBackgroundBrush}"> - <TextBlock x:Name="GlyphElement" - Foreground="{ThemeResource FormsCancelForegroundBrush}" - VerticalAlignment="Center" - HorizontalAlignment="Center" - FontStyle="Normal" - FontSize="12" - Text="" - FontFamily="{ThemeResource SymbolThemeFontFamily}" - AutomationProperties.AccessibilityView="Raw"/> - </Border> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> - <Style x:Name="QueryButtonStyle" TargetType="Button"> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="Button"> - <Grid> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="CommonStates"> - <VisualState x:Name="Normal" /> - <VisualState x:Name="PointerOver"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAccentBrush}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Pressed"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Disabled"> - <Storyboard> - <DoubleAnimation Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Opacity" - To="0" - Duration="0" /> - </Storyboard> - </VisualState> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <Border x:Name="BorderElement" - BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}" - BorderThickness="{TemplateBinding BorderThickness}" - Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}"> - <ContentPresenter x:Name="ContentPresenter" - Content="{TemplateBinding Content}" - ContentTransitions="{TemplateBinding ContentTransitions}" - ContentTemplate="{TemplateBinding ContentTemplate}" - Margin="{TemplateBinding Padding}" - HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" - VerticalAlignment="{TemplateBinding VerticalContentAlignment}" - AutomationProperties.AccessibilityView="Raw"/> - </Border> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> - </Grid.Resources> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="CommonStates"> - <VisualState x:Name="Disabled"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="BorderBrush"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Normal" /> - <VisualState x:Name="PointerOver"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="BorderBrush"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightChromeAltLowBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" - Storyboard.TargetProperty="Opacity"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Focused"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" - Storyboard.TargetProperty="Background"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" - Storyboard.TargetProperty="Opacity"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocusedOpacity}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" - Storyboard.TargetProperty="BorderBrush"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding ForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" - Storyboard.TargetProperty="RequestedTheme"> - <DiscreteObjectKeyFrame KeyTime="0" Value="Light" /> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="QueryButton" - Storyboard.TargetProperty="Foreground"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundChromeBlackMediumBrush}" /> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - </VisualStateGroup> - <VisualStateGroup x:Name="ButtonStates"> - <VisualState x:Name="ButtonVisible"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" - Storyboard.TargetProperty="Visibility"> - <DiscreteObjectKeyFrame KeyTime="0"> - <DiscreteObjectKeyFrame.Value> - <Visibility>Visible</Visibility> - </DiscreteObjectKeyFrame.Value> - </DiscreteObjectKeyFrame> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="ButtonCollapsed" /> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="*" /> - <ColumnDefinition Width="Auto" /> - <ColumnDefinition Width="Auto" /> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> - <Border x:Name="BackgroundElement" - Grid.Row="1" - Background="{TemplateBinding Background}" - Margin="{TemplateBinding BorderThickness}" - Opacity="{ThemeResource TextControlBackgroundRestOpacity}" - Grid.ColumnSpan="3" - Grid.RowSpan="1"/> - <Border x:Name="BorderElement" - Grid.Row="1" - BorderBrush="{TemplateBinding BorderBrush}" - BorderThickness="{TemplateBinding BorderThickness}" - Grid.ColumnSpan="3" - Grid.RowSpan="1"/> - <ContentPresenter x:Name="HeaderContentPresenter" - x:DeferLoadStrategy="Lazy" - Visibility="Collapsed" - Grid.Row="0" - Foreground="{Binding PlaceholderForegroundBrush, RelativeSource={RelativeSource TemplatedParent}}" - Margin="0,0,0,8" - Grid.ColumnSpan="3" - Content="{TemplateBinding Header}" - ContentTemplate="{TemplateBinding HeaderTemplate}" - FontWeight="Normal" - TextWrapping="Wrap" /> - <ScrollViewer x:Name="ContentElement" - Grid.Row="1" - HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" - HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" - VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" - VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" - IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" - IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" - IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" - Margin="{TemplateBinding BorderThickness}" - Padding="{TemplateBinding Padding}" - IsTabStop="False" - AutomationProperties.AccessibilityView="Raw" - ZoomMode="Disabled" /> - <!-- Converting the TextAlignment set for the control's input text to a HorizontalAlignment - so the PlaceholderText's alignment will match the input text --> - <ContentControl x:Name="PlaceholderTextContentPresenter" - Grid.Row="1" - Foreground="{Binding PlaceholderForegroundBrush, RelativeSource={RelativeSource TemplatedParent}}" - Margin="{TemplateBinding BorderThickness}" - Padding="{TemplateBinding Padding}" - IsTabStop="False" - Grid.ColumnSpan="3" - Content="{TemplateBinding PlaceholderText}" - FontFamily="{TemplateBinding FontFamily}" - FontSize="{TemplateBinding FontSize}" - FontStyle="{TemplateBinding FontStyle}" - IsHitTestVisible="False" - HorizontalAlignment="{Binding TextAlignment, - RelativeSource={RelativeSource Mode=TemplatedParent}, - Converter={StaticResource AlignmentConverter}}" /> - <Button x:Name="DeleteButton" - Grid.Row="1" - Style="{StaticResource DeleteButtonStyle}" - BorderThickness="{TemplateBinding BorderThickness}" - Margin="{ThemeResource HelperButtonThemePadding}" - IsTabStop="False" - Grid.Column="1" - Visibility="Collapsed" - FontSize="{TemplateBinding FontSize}" - MinWidth="34" - VerticalAlignment="Stretch"/> - <Button x:Name="QueryButton" - Grid.Row="1" - Style="{StaticResource QueryButtonStyle}" - BorderThickness="{TemplateBinding BorderThickness}" - Margin="{ThemeResource HelperButtonThemePadding}" - IsTabStop="False" - Grid.Column="2" - FontSize="{TemplateBinding FontSize}" - MinWidth="34" - VerticalAlignment="Stretch"/> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> + </ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/SearchBarRenderer.cs b/Xamarin.Forms.Platform.UAP/SearchBarRenderer.cs index 04e1058a..9b80ade1 100644 --- a/Xamarin.Forms.Platform.UAP/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/SearchBarRenderer.cs @@ -155,23 +155,11 @@ namespace Xamarin.Forms.Platform.UWP Color placeholderColor = Element.PlaceholderColor; - if (placeholderColor.IsDefault) - { - if (_defaultPlaceholderColorBrush == null) - return; - - _queryTextBox.PlaceholderForegroundBrush = _defaultPlaceholderColorBrush; - _queryTextBox.PlaceholderForegroundBrush = _defaultPlaceholderColorFocusBrush; - } - - if (_defaultPlaceholderColorBrush == null) - { - _defaultPlaceholderColorBrush = _queryTextBox.PlaceholderForegroundBrush; - _defaultPlaceholderColorFocusBrush = _queryTextBox.PlaceholderForegroundFocusBrush; - } + BrushHelpers.UpdateColor(placeholderColor, ref _defaultPlaceholderColorBrush, + () => _queryTextBox.PlaceholderForegroundBrush, brush => _queryTextBox.PlaceholderForegroundBrush = brush); - _queryTextBox.PlaceholderForegroundBrush = placeholderColor.ToBrush(); - _queryTextBox.PlaceholderForegroundFocusBrush = placeholderColor.ToBrush(); + BrushHelpers.UpdateColor(placeholderColor, ref _defaultPlaceholderColorFocusBrush, + () => _queryTextBox.PlaceholderForegroundFocusBrush, brush => _queryTextBox.PlaceholderForegroundFocusBrush = brush); } void UpdateText() @@ -186,23 +174,11 @@ namespace Xamarin.Forms.Platform.UWP Color textColor = Element.TextColor; - if (textColor.IsDefault) - { - if (_defaultTextColorBrush == null) - return; - - _queryTextBox.Foreground = _defaultTextColorBrush; - _queryTextBox.ForegroundFocusBrush = _defaultTextColorFocusBrush; - } - - if (_defaultTextColorBrush == null) - { - _defaultTextColorBrush = _queryTextBox.Foreground; - _defaultTextColorFocusBrush = _queryTextBox.ForegroundFocusBrush; - } + BrushHelpers.UpdateColor(textColor, ref _defaultTextColorBrush, + () => _queryTextBox.Foreground, brush => _queryTextBox.Foreground = brush); - _queryTextBox.Foreground = textColor.ToBrush(); - _queryTextBox.ForegroundFocusBrush = textColor.ToBrush(); + BrushHelpers.UpdateColor(textColor, ref _defaultTextColorFocusBrush, + () => _queryTextBox.ForegroundFocusBrush, brush => _queryTextBox.ForegroundFocusBrush = brush); } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj index 5ce6221e..4e804819 100644 --- a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj +++ b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj @@ -131,6 +131,9 @@ <Compile Include="..\Xamarin.Forms.Platform.WinRT\AlignmentExtensions.cs"> <Link>AlignmentExtensions.cs</Link> </Compile> + <Compile Include="..\Xamarin.Forms.Platform.WinRT\BrushHelpers.cs"> + <Link>BrushHelpers.cs</Link> + </Compile> <Compile Include="..\Xamarin.Forms.Platform.WinRT\FormsTextBox.cs"> <Link>FormsTextBox.cs</Link> </Compile> @@ -421,6 +424,10 @@ <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> + <Page Include="AutoSuggestStyle.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="FormsTextBoxStyle.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/Xamarin.Forms.Platform.WP8/BrushHelpers.cs b/Xamarin.Forms.Platform.WP8/BrushHelpers.cs new file mode 100644 index 00000000..993b23f4 --- /dev/null +++ b/Xamarin.Forms.Platform.WP8/BrushHelpers.cs @@ -0,0 +1,37 @@ +using System; +using System.Windows.Media; + +namespace Xamarin.Forms.Platform.WinPhone +{ + internal static class BrushHelpers + { + /// <summary> + /// Handles the logic for setting a Xamarin.Forms Color for a Brush + /// while caching the original default brush + /// </summary> + /// <param name="color">The target Xamarin.Forms.Color</param> + /// <param name="defaultbrush">The renderer's cache for the default brush</param> + /// <param name="getter">Delegate for retrieving the Control's current Brush</param> + /// <param name="setter">Delegate for setting the Control's Brush</param> + public static void UpdateColor(Color color, ref Brush defaultbrush, Func<Brush> getter, Action<Brush> setter) + { + if (color.IsDefault) + { + if (defaultbrush == null) + { + return; + } + + setter(defaultbrush); + return; + } + + if (defaultbrush == null) + { + defaultbrush = getter(); + } + + setter(color.ToBrush()); + } + } +} diff --git a/Xamarin.Forms.Platform.WP8/EntryRenderer.cs b/Xamarin.Forms.Platform.WP8/EntryRenderer.cs index b2749c05..00fdbb4a 100644 --- a/Xamarin.Forms.Platform.WP8/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.WP8/EntryRenderer.cs @@ -77,6 +77,7 @@ namespace Xamarin.Forms.Platform.WinPhone bool _fontApplied; bool _ignoreTextChange; Brush _placeholderDefaultBrush; + Brush _textDefaultBrush; public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { @@ -216,23 +217,12 @@ namespace Xamarin.Forms.Platform.WinPhone if (Control == null) return; - Entry entry = Element; - if (entry != null) - { - if (!IsNullOrEmpty(entry.Text)) - { - if (!entry.TextColor.IsDefault) - Control.Foreground = entry.TextColor.ToBrush(); - else - Control.Foreground = (Brush)WControl.ForegroundProperty.GetMetadata(typeof(FormsPhoneTextBox)).DefaultValue; - - // Force the PhoneTextBox control to do some internal bookkeeping - // so the colors change immediately and remain changed when the control gets focus - Control.OnApplyTemplate(); - } - } - else - Control.Foreground = (Brush)WControl.ForegroundProperty.GetMetadata(typeof(FormsPhoneTextBox)).DefaultValue; + BrushHelpers.UpdateColor(Element.TextColor, ref _textDefaultBrush, + () => Control.Foreground, brush => Control.Foreground = brush); + + // Force the PhoneTextBox control to do some internal bookkeeping + // so the colors change immediately and remain changed when the control gets focus + Control.OnApplyTemplate(); } void UpdateFont() @@ -286,25 +276,8 @@ namespace Xamarin.Forms.Platform.WinPhone void UpdatePlaceholderColor() { - Color placeholderColor = Element.PlaceholderColor; - - if (placeholderColor.IsDefault) - { - if (_placeholderDefaultBrush == null) - return; - - // Use the cached default brush - Control.PlaceholderForegroundBrush = _placeholderDefaultBrush; - return; - } - - if (_placeholderDefaultBrush == null) - { - // Cache the default brush in case we need to set the color back to default - _placeholderDefaultBrush = Control.PlaceholderForegroundBrush; - } - - Control.PlaceholderForegroundBrush = placeholderColor.ToBrush(); + BrushHelpers.UpdateColor(Element.PlaceholderColor, ref _placeholderDefaultBrush, + () => Control.PlaceholderForegroundBrush, brush => Control.PlaceholderForegroundBrush = brush); } void UpdateText() diff --git a/Xamarin.Forms.Platform.WP8/SearchBarRenderer.cs b/Xamarin.Forms.Platform.WP8/SearchBarRenderer.cs index a71041da..b37978d0 100644 --- a/Xamarin.Forms.Platform.WP8/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.WP8/SearchBarRenderer.cs @@ -117,20 +117,8 @@ namespace Xamarin.Forms.Platform.WinPhone void UpdatePlaceholderColor() { - Color placeholderColor = Element.PlaceholderColor; - - if (placeholderColor.IsDefault) - { - if (_defaultPlaceholderColorBrush == null) - return; - - Control.PlaceholderForegroundBrush = _defaultPlaceholderColorBrush; - } - - if (_defaultPlaceholderColorBrush == null) - _defaultPlaceholderColorBrush = Control.PlaceholderForegroundBrush; - - Control.PlaceholderForegroundBrush = placeholderColor.ToBrush(); + BrushHelpers.UpdateColor(Element.PlaceholderColor, ref _defaultPlaceholderColorBrush, + () => Control.PlaceholderForegroundBrush, brush => Control.PlaceholderForegroundBrush = brush); } void UpdateText() @@ -140,20 +128,12 @@ namespace Xamarin.Forms.Platform.WinPhone void UpdateTextColor() { - Color textColor = Element.TextColor; - - if (textColor.IsDefault) - { - if (_defaultTextColorBrush == null) - return; - - Control.Foreground = _defaultTextColorBrush; - } - - if (_defaultTextColorBrush == null) - _defaultTextColorBrush = Control.Foreground; - - Control.Foreground = textColor.ToBrush(); + BrushHelpers.UpdateColor(Element.TextColor, ref _defaultTextColorBrush, + () => Control.Foreground, brush => Control.Foreground = brush); + + // Force the PhoneTextBox control to do some internal bookkeeping + // so the colors change immediately and remain changed when the control gets focus + Control.OnApplyTemplate(); } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj b/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj index eda2cdce..e78234f5 100644 --- a/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj +++ b/Xamarin.Forms.Platform.WP8/Xamarin.Forms.Platform.WP8.csproj @@ -142,6 +142,7 @@ <Compile Include="AlignmentExtensions.cs" /> <Compile Include="Animatable.cs" /> <Compile Include="AsyncValue.cs" /> + <Compile Include="BrushHelpers.cs" /> <Compile Include="CellControl.cs" /> <Compile Include="CollapseWhenEmptyConverter.cs" /> <Compile Include="Deserializer.cs" /> diff --git a/Xamarin.Forms.Platform.WinRT/BrushHelpers.cs b/Xamarin.Forms.Platform.WinRT/BrushHelpers.cs new file mode 100644 index 00000000..ae158b8f --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT/BrushHelpers.cs @@ -0,0 +1,43 @@ +using System; +using Windows.UI.Xaml.Media; + +#if WINDOWS_UWP + +namespace Xamarin.Forms.Platform.UWP +#else + +namespace Xamarin.Forms.Platform.WinRT +#endif +{ + internal static class BrushHelpers + { + /// <summary> + /// Handles the logic for setting a Xamarin.Forms Color for a Brush + /// while caching the original default brush + /// </summary> + /// <param name="color">The target Xamarin.Forms.Color</param> + /// <param name="defaultbrush">The renderer's cache for the default brush</param> + /// <param name="getter">Delegate for retrieving the Control's current Brush</param> + /// <param name="setter">Delegate for setting the Control's Brush</param> + public static void UpdateColor(Color color, ref Brush defaultbrush, Func<Brush> getter, Action<Brush> setter) + { + if (color.IsDefault) + { + if (defaultbrush == null) + { + return; + } + + setter(defaultbrush); + return; + } + + if (defaultbrush == null) + { + defaultbrush = getter(); + } + + setter(color.ToBrush()); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs b/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs index f9f0b3a2..c6e439ea 100644 --- a/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/EntryRenderer.cs @@ -1,4 +1,7 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; +using System.Reflection; +using Windows.Foundation.Metadata; using Windows.System; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; @@ -13,10 +16,12 @@ namespace Xamarin.Forms.Platform.WinRT { public class EntryRenderer : ViewRenderer<Entry, FormsTextBox> { - Brush _backgroundColorFocusedDefaultBrush; - bool _fontApplied; + Brush _backgroundColorFocusedDefaultBrush; Brush _placeholderDefaultBrush; + Brush _textDefaultBrush; + Brush _defaultTextColorFocusBrush; + Brush _defaultPlaceholderColorFocusBrush; protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { @@ -27,7 +32,6 @@ namespace Xamarin.Forms.Platform.WinRT if (Control == null) { var textBox = new FormsTextBox { Style = Windows.UI.Xaml.Application.Current.Resources["FormsTextBoxStyle"] as Windows.UI.Xaml.Style }; - SetNativeControl(textBox); textBox.TextChanged += OnNativeTextChanged; @@ -92,24 +96,8 @@ namespace Xamarin.Forms.Platform.WinRT } // By default some platforms have alternate default background colors when focused - Color backgroundColor = Element.BackgroundColor; - if (backgroundColor.IsDefault) - { - if (_backgroundColorFocusedDefaultBrush == null) - { - return; - } - - Control.BackgroundFocusBrush = _backgroundColorFocusedDefaultBrush; - return; - } - - if (_backgroundColorFocusedDefaultBrush == null) - { - _backgroundColorFocusedDefaultBrush = Control.BackgroundFocusBrush; - } - - Control.BackgroundFocusBrush = backgroundColor.ToBrush(); + BrushHelpers.UpdateColor(Element.BackgroundColor, ref _backgroundColorFocusedDefaultBrush, + () => Control.BackgroundFocusBrush, brush => Control.BackgroundFocusBrush = brush); } void OnNativeTextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs args) @@ -190,25 +178,11 @@ namespace Xamarin.Forms.Platform.WinRT { Color placeholderColor = Element.PlaceholderColor; - if (placeholderColor.IsDefault) - { - if (_placeholderDefaultBrush == null) - { - return; - } - - // Use the cached default brush - Control.PlaceholderForegroundBrush = _placeholderDefaultBrush; - return; - } - - if (_placeholderDefaultBrush == null) - { - // Cache the default brush in case we need to set the color back to default - _placeholderDefaultBrush = Control.PlaceholderForegroundBrush; - } + BrushHelpers.UpdateColor(placeholderColor, ref _placeholderDefaultBrush, + () => Control.PlaceholderForegroundBrush, brush => Control.PlaceholderForegroundBrush = brush); - Control.PlaceholderForegroundBrush = placeholderColor.ToBrush(); + BrushHelpers.UpdateColor(placeholderColor, ref _defaultPlaceholderColorFocusBrush, + () => Control.PlaceholderForegroundFocusBrush, brush => Control.PlaceholderForegroundFocusBrush = brush); } void UpdateText() @@ -218,7 +192,13 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateTextColor() { - Control.Foreground = Element.TextColor.ToBrush(); + Color textColor = Element.TextColor; + + BrushHelpers.UpdateColor(textColor, ref _textDefaultBrush, + () => Control.Foreground, brush => Control.Foreground = brush); + + BrushHelpers.UpdateColor(textColor, ref _defaultTextColorFocusBrush, + () => Control.ForegroundFocusBrush, brush => Control.ForegroundFocusBrush = brush); } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs b/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs index 03725cd8..4cb74ec7 100644 --- a/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs +++ b/Xamarin.Forms.Platform.WinRT/FormsTextBox.cs @@ -23,19 +23,19 @@ namespace Xamarin.Forms.Platform.WinRT { const char ObfuscationCharacter = '●'; - public static readonly DependencyProperty PlaceholderForegroundBrushProperty = DependencyProperty.Register("PlaceholderForegroundBrush", typeof(Brush), typeof(FormsTextBox), + public static readonly DependencyProperty PlaceholderForegroundBrushProperty = DependencyProperty.Register(nameof(PlaceholderForegroundBrush), typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush))); - public static readonly DependencyProperty PlaceholderForegroundFocusBrushProperty = DependencyProperty.Register("PlaceholderForegroundFocusBrush", typeof(Brush), typeof(FormsTextBox), + public static readonly DependencyProperty PlaceholderForegroundFocusBrushProperty = DependencyProperty.Register(nameof(PlaceholderForegroundFocusBrush), typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush))); - public static readonly DependencyProperty ForegroundFocusBrushProperty = DependencyProperty.Register("ForegroundFocusBrush", typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush))); + public static readonly DependencyProperty ForegroundFocusBrushProperty = DependencyProperty.Register(nameof(ForegroundFocusBrush), typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush))); - public static readonly DependencyProperty BackgroundFocusBrushProperty = DependencyProperty.Register("BackgroundFocusBrush", typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush))); + public static readonly DependencyProperty BackgroundFocusBrushProperty = DependencyProperty.Register(nameof(BackgroundFocusBrush), typeof(Brush), typeof(FormsTextBox), new PropertyMetadata(default(Brush))); - public static readonly DependencyProperty IsPasswordProperty = DependencyProperty.Register("IsPassword", typeof(bool), typeof(FormsTextBox), new PropertyMetadata(default(bool), OnIsPasswordChanged)); + public static readonly DependencyProperty IsPasswordProperty = DependencyProperty.Register(nameof(IsPassword), typeof(bool), typeof(FormsTextBox), new PropertyMetadata(default(bool), OnIsPasswordChanged)); - public new static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(FormsTextBox), new PropertyMetadata("", TextPropertyChanged)); + public new static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(FormsTextBox), new PropertyMetadata("", TextPropertyChanged)); static InputScope s_passwordInputScope; Border _borderElement; @@ -120,13 +120,15 @@ namespace Xamarin.Forms.Platform.WinRT { base.OnGotFocus(e); - // If we're on the phone, the Visual State Manager crashes if we try to +#if !WINDOWS_UWP + // If we're on Windows 8.1 phone, the Visual State Manager crashes if we try to // handle alternate background colors in the focus state; we have to do // it manually here if (Device.Idiom == TargetIdiom.Phone && _borderElement != null) { _borderElement.Background = BackgroundFocusBrush; } +#endif } void DelayObfuscation() diff --git a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj index f6b3566a..400737d0 100644 --- a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj +++ b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj @@ -68,6 +68,7 @@ </Compile> </ItemGroup> <ItemGroup Condition=" '$(OS)' != 'Unix' "> + <Compile Include="BrushHelpers.cs" /> <Compile Include="NativeViewWrapper.cs" /> <Compile Include="NativeViewWrapperRenderer.cs" /> <Compile Include="ViewExtensions.cs" /> |