Created
May 4, 2020 02:59
-
-
Save colinkiama/9230d91d9343c3a0c552eb2556bba25f to your computer and use it in GitHub Desktop.
UWP TextBox style that's lightweight (No borders, no background. Just text
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
<Style TargetType="TextBox" x:Key="LightweightTextBoxStyle"> | |
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" /> | |
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" /> | |
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" /> | |
<Setter Property="Background" Value="{ThemeResource TextControlBackground}" /> | |
<Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}" /> | |
<Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}" /> | |
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" /> | |
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> | |
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> | |
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto" /> | |
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" /> | |
<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="TextBox"> | |
<Grid> | |
<VisualStateManager.VisualStateGroups> | |
<VisualStateGroup x:Name="CommonStates"> | |
<VisualState x:Name="Disabled"> | |
<Storyboard> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" Storyboard.TargetProperty="Foreground"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlHeaderForegroundDisabled}" /> | |
</ObjectAnimationUsingKeyFrames> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundDisabled}" /> | |
</ObjectAnimationUsingKeyFrames> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderBrushDisabled}" /> | |
</ObjectAnimationUsingKeyFrames> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundDisabled}" /> | |
</ObjectAnimationUsingKeyFrames> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlPlaceholderForegroundDisabled}" /> | |
</ObjectAnimationUsingKeyFrames> | |
</Storyboard> | |
</VisualState> | |
<VisualState x:Name="Normal" /> | |
<VisualState x:Name="PointerOver"> | |
<Storyboard> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlPlaceholderForegroundPointerOver}" /> | |
</ObjectAnimationUsingKeyFrames> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundPointerOver}" /> | |
</ObjectAnimationUsingKeyFrames> | |
</Storyboard> | |
</VisualState> | |
<VisualState x:Name="Focused"> | |
<Storyboard> | |
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground"> | |
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> | |
</ObjectAnimationUsingKeyFrames> | |
</Storyboard> | |
</VisualState> | |
</VisualStateGroup> | |
</VisualStateManager.VisualStateGroups> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="*" /> | |
<ColumnDefinition Width="Auto" /> | |
</Grid.ColumnDefinitions> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="Auto" /> | |
<RowDefinition Height="*" /> | |
</Grid.RowDefinitions> | |
<Border x:Name="BorderElement" | |
Grid.Row="1" | |
Background="{TemplateBinding Background}" | |
BorderBrush="{TemplateBinding BorderBrush}" | |
BorderThickness="{TemplateBinding BorderThickness}" | |
Grid.ColumnSpan="2" | |
Grid.RowSpan="1" /> | |
<ContentPresenter x:Name="HeaderContentPresenter" | |
x:DeferLoadStrategy="Lazy" | |
Visibility="Collapsed" | |
Grid.Row="0" | |
Foreground="{ThemeResource TextControlHeaderForeground}" | |
Margin="0,0,0,8" | |
Grid.ColumnSpan="2" | |
Content="{TemplateBinding Header}" | |
ContentTemplate="{TemplateBinding HeaderTemplate}" | |
FontWeight="Normal" /> | |
<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" /> | |
<ContentControl x:Name="PlaceholderTextContentPresenter" | |
Grid.Row="1" | |
Foreground="{ThemeResource TextControlPlaceholderForeground}" | |
Margin="{TemplateBinding BorderThickness}" | |
Padding="{TemplateBinding Padding}" | |
IsTabStop="False" | |
Grid.ColumnSpan="2" | |
Content="{TemplateBinding PlaceholderText}" | |
IsHitTestVisible="False" /> | |
</Grid> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment