C# 文本框内的奇怪十字架

C# 文本框内的奇怪十字架,c#,xaml,textbox,windows-store-apps,winrt-xaml,C#,Xaml,Textbox,Windows Store Apps,Winrt Xaml,TextBox有问题。如果我像NoWrap那样设置属性TextWrap,我会在文本框中看到一个叉号。我可以删除或隐藏这个十字架吗 UPD:我的问题的解决方案: 设置TextWrap类似Wrap 我使用FontSize72px,并为我的TextBox72px设置Height 它看起来像你的文本框,里面没有多行和十字。十字是内置的删除按钮,如果你在该链接中查看它并转到默认模板的底部,你会看到模板底部的删除按钮按钮。您可以在那里删除它,也可以按照我在上一篇文章中显示的方式删除它。:) 要访问模板(最

TextBox
有问题。如果我像
NoWrap
那样设置属性
TextWrap
,我会在
文本框中看到一个叉号。我可以删除或隐藏这个十字架吗

UPD:我的问题的解决方案:

  • 设置
    TextWrap
    类似
    Wrap
  • 我使用
    FontSize
    72px,并为我的
    TextBox
    72px设置
    Height

  • 它看起来像你的
    文本框
    ,里面没有多行和十字。

    十字是内置的
    删除按钮
    ,如果你在该链接中查看它并转到默认模板的底部,你会看到模板底部的
    删除按钮
    按钮
    。您可以在那里删除它,也可以按照我在上一篇文章中显示的方式删除它。:)

    要访问模板(最快的方式),请右键单击
    文本框
    ,选择“编辑模板”,然后编辑一份副本(这将把模板放在您的window.resources中)并明确定义它,或者编辑原始模板

    PS-你可以将你在上一篇文章中的图片添加到这篇文章中,供家中的观众观看

    出于对上帝的爱和理智而编辑

    伙计,这是一个默认模板的副本,按钮被移除了。只需将它放在您的UserControl.Resources或Window.Resources或Application.Resources中,或者放在可以作为静态资源找到的地方

        <!-- Default style for Windows.UI.Xaml.Controls.TextBox 
             With the DeleteButton removed and given an explicit key name -->
        <Style TargetType="TextBox" x:Key="LearningToEditControlsTodayYAY">
            <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
            <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
            <Setter Property="Foreground" Value="{ThemeResource TextBoxForegroundThemeBrush}" />
            <Setter Property="Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}" />
            <Setter Property="BorderBrush" Value="{ThemeResource TextBoxBorderThemeBrush}" />
            <Setter Property="SelectionHighlightColor" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}" />
            <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="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.TargetName="BackgroundElement"
                                                                                                   Storyboard.TargetProperty="Background">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxButtonPointerOverBackgroundThemeBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
                                                                                                   Storyboard.TargetProperty="BorderBrush">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxButtonPointerOverBorderThemeBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
                                                                                                   Storyboard.TargetProperty="Foreground">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxButtonPointerOverForegroundThemeBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </VisualState>
                                                            <VisualState x:Name="Pressed">
                                                                <Storyboard>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
                                                                                                   Storyboard.TargetProperty="Background">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxButtonPressedBackgroundThemeBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
                                                                                                   Storyboard.TargetProperty="BorderBrush">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxButtonPressedBorderThemeBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
                                                                                                   Storyboard.TargetProperty="Foreground">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxButtonPressedForegroundThemeBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </VisualState>
                                                            <VisualState x:Name="Disabled">
                                                                <Storyboard>
                                                                    <DoubleAnimation Storyboard.TargetName="BackgroundElement"
                                                                                     Storyboard.TargetProperty="Opacity"
                                                                                     To="0"
                                                                                     Duration="0" />
                                                                    <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}"/>
                                                    <Border x:Name="BackgroundElement"
                                                            Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}"
                                                            Margin="{TemplateBinding BorderThickness}">
                                                        <TextBlock x:Name="GlyphElement"
                                                                   Foreground="{ThemeResource TextBoxButtonForegroundThemeBrush}"
                                                                   VerticalAlignment="Center"
                                                                   HorizontalAlignment="Center"
                                                                   FontStyle="Normal"
                                                                   Text="&#xE0A4;"
                                                                   FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                                                   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="BackgroundElement"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
                                                                           Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
                                                                           Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter"
                                                                           Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="BackgroundElement"
                                                             Storyboard.TargetProperty="Opacity"
                                                             Duration="0"
                                                             To="{ThemeResource TextControlBackgroundThemeOpacity}" />
                                            <DoubleAnimation Storyboard.TargetName="BorderElement"
                                                             Storyboard.TargetProperty="Opacity"
                                                             Duration="0"
                                                             To="{ThemeResource TextControlBorderThemeOpacity}" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="BackgroundElement"
                                                             Storyboard.TargetProperty="Opacity"
                                                             Duration="0"
                                                             To="{ThemeResource TextControlPointerOverBackgroundThemeOpacity}" />
                                            <DoubleAnimation Storyboard.TargetName="BorderElement"
                                                             Storyboard.TargetProperty="Opacity"
                                                             Duration="0"
                                                             To="{ThemeResource TextControlPointerOverBorderThemeOpacity}" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Focused" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ButtonStates">
                                    <VisualState x:Name="ButtonVisible">
    <!-- ********************************
            SEE THIS, THIS IS WHERE IT'S TELLING THAT BUTTON TO SHOW ON THE "ButtonVisible" State,
            WHICH IF WE JUST COMMENT THIS OUT, MAKES IT GO AWAY. However I would also clean out the Button object and remove the unnecessary extra columndefinitions from the grid that holds it, but I'll leave that to you amigo....
    ***************************************** -->
    <!--
                                        <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" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Border x:Name="BackgroundElement"
                                    Grid.Row="1"
                                    Background="{TemplateBinding Background}"
                                    Margin="{TemplateBinding BorderThickness}"
                                    Grid.ColumnSpan="2"
                                    Grid.RowSpan="1"/>
                            <Border x:Name="BorderElement"
                                    Grid.Row="1"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Grid.ColumnSpan="2"
                                    Grid.RowSpan="1"/>
                            <ContentPresenter x:Name="HeaderContentPresenter"
                                              Grid.Row="0"
                                              Foreground="{ThemeResource TextBoxForegroundHeaderThemeBrush}"
                                              Margin="0,4,0,4"
                                              Grid.ColumnSpan="2"
                                              Content="{TemplateBinding Header}"
                                              ContentTemplate="{TemplateBinding HeaderTemplate}"
                                              FontWeight="Semilight" />
                            <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 TextBoxPlaceholderTextThemeBrush}"
                                          Margin="{TemplateBinding BorderThickness}"
                                          Padding="{TemplateBinding Padding}"
                                          IsTabStop="False"
                                          Grid.ColumnSpan="2"
                                          Content="{TemplateBinding PlaceholderText}" 
                                          IsHitTestVisible="False"/>
    
    <!-- *******************
         SEE THIS HERE, THIS IS THE BUTTON YOU WANT GONE
    -->
                            <Button x:Name="DeleteButton"
                                    Grid.Row="1"
                                    Style="{StaticResource DeleteButtonStyle}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    IsTabStop="False"
                                    Grid.Column="1"
                                    Visibility="Collapsed"
                                    FontSize="{TemplateBinding FontSize}"
                                    VerticalAlignment="Stretch"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>