none
How to remove default 'X' mark from Text box ?

    Question

  • Hi,

    I have added simple Text box which contains some text value, when problematically i set focus to text box it shows the default 'X' on right corner of TextBox having default 'clear' functionality. 

    Please suggest me the way to remove this cross mark from textbox.   


    C Mahone

    Tuesday, January 15, 2013 3:49 PM

Answers

  • Delete button of TextBox is Collapsed always, but Visibility will be changed on different visual states. So just comment out or remove the visual state/style/delete button like this : 

    <Style x:Key="TextBoxWithoutDelete" TargetType="TextBox">
    			<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}"/>
    			<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}"/>
    			<Setter Property="Foreground" Value="{StaticResource TextBoxForegroundThemeBrush}"/>
    			<Setter Property="Background" Value="{StaticResource TextBoxBackgroundThemeBrush}"/>
    			<Setter Property="BorderBrush" Value="{StaticResource TextBoxBorderThemeBrush}"/>
    			<Setter Property="BorderThickness" Value="{StaticResource TextControlBorderThemeThickness}"/>
    			<Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
    			<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/>
    			<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/>
    			<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/>
    			<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
    			<Setter Property="Padding" Value="{StaticResource TextControlThemePadding}"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="TextBox">
    						<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.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
    																		<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxButtonPointerOverBackgroundThemeBrush}"/>
    																	</ObjectAnimationUsingKeyFrames>
    																	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
    																		<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxButtonPointerOverBorderThemeBrush}"/>
    																	</ObjectAnimationUsingKeyFrames>
    																	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="GlyphElement">
    																		<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxButtonPointerOverForegroundThemeBrush}"/>
    																	</ObjectAnimationUsingKeyFrames>
    																</Storyboard>
    															</VisualState>
    															<VisualState x:Name="Pressed">
    																<Storyboard>
    																	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
    																		<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxButtonPressedBackgroundThemeBrush}"/>
    																	</ObjectAnimationUsingKeyFrames>
    																	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
    																		<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxButtonPressedBorderThemeBrush}"/>
    																	</ObjectAnimationUsingKeyFrames>
    																	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="GlyphElement">
    																		<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxButtonPressedForegroundThemeBrush}"/>
    																	</ObjectAnimationUsingKeyFrames>
    																</Storyboard>
    															</VisualState>
    															<VisualState x:Name="Disabled">
    																<Storyboard>
    																	<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement"/>
    																	<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/>
    																</Storyboard>
    															</VisualState>
    														</VisualStateGroup>
    													</VisualStateManager.VisualStateGroups>
    													<Border x:Name="BorderElement" BorderBrush="{StaticResource TextBoxButtonBorderThemeBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
    													<Border x:Name="BackgroundElement" Background="{StaticResource TextBoxButtonBackgroundThemeBrush}" Margin="{TemplateBinding BorderThickness}">
    														<TextBlock x:Name="GlyphElement" Foreground="{StaticResource TextBoxButtonForegroundThemeBrush}" FontFamily="{StaticResource SymbolThemeFontFamily}" HorizontalAlignment="Center" Text="&#xE0A4;" VerticalAlignment="Center"/>
    													</Border>
    												</Grid>
    											</ControlTemplate>
    										</Setter.Value>
    									</Setter>
    								</Style>-->
    							</Grid.Resources>
    							<Grid.ColumnDefinitions>
    								<ColumnDefinition Width="*"/>
    								<ColumnDefinition Width="Auto"/>
    							</Grid.ColumnDefinitions>
    							<VisualStateManager.VisualStateGroups>
    								<VisualStateGroup x:Name="CommonStates">
    									<VisualState x:Name="Disabled">
    										<Storyboard>
    											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
    												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxDisabledBackgroundThemeBrush}"/>
    											</ObjectAnimationUsingKeyFrames>
    											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
    												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxDisabledBorderThemeBrush}"/>
    											</ObjectAnimationUsingKeyFrames>
    											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement">
    												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxDisabledForegroundThemeBrush}"/>
    											</ObjectAnimationUsingKeyFrames>
    										</Storyboard>
    									</VisualState>
    									<VisualState x:Name="Normal">
    										<Storyboard>
    											<DoubleAnimation Duration="0" To="{StaticResource TextControlBackgroundThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement"/>
    											<DoubleAnimation Duration="0" To="{StaticResource TextControlBorderThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/>
    										</Storyboard>
    									</VisualState>
    									<VisualState x:Name="PointerOver">
    										<Storyboard>
    											<DoubleAnimation Duration="0" To="{StaticResource TextControlPointerOverBackgroundThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement"/>
    											<DoubleAnimation Duration="0" To="{StaticResource TextControlPointerOverBorderThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/>
    										</Storyboard>
    									</VisualState>
    									<VisualState x:Name="Focused"/>
    								</VisualStateGroup>
    								<VisualStateGroup x:Name="ButtonStates">
    									<VisualState x:Name="ButtonVisible">
    										<!--<Storyboard>
    											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DeleteButton">
    												<DiscreteObjectKeyFrame KeyTime="0">
    													<DiscreteObjectKeyFrame.Value>
    														<Visibility>Visible</Visibility>
    													</DiscreteObjectKeyFrame.Value>
    												</DiscreteObjectKeyFrame>
    											</ObjectAnimationUsingKeyFrames>
    										</Storyboard>-->
    									</VisualState>
    									<VisualState x:Name="ButtonCollapsed"/>
    								</VisualStateGroup>
    							</VisualStateManager.VisualStateGroups>
    							<Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" Margin="{TemplateBinding BorderThickness}"/>
    							<Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2"/>
    							<ScrollViewer x:Name="ContentElement" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsTabStop="False" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled"/>
    							<!--<Button x:Name="DeleteButton" BorderThickness="{TemplateBinding BorderThickness}" Grid.Column="1" FontSize="{TemplateBinding FontSize}" IsTabStop="False" Style="{StaticResource DeleteButtonStyle}" Visibility="Collapsed" VerticalAlignment="Stretch"/>-->
    						</Grid>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, January 15, 2013 4:08 PM