繁体   English   中英

C#XAML通用应用程序摆脱了TextBoxes的“蒙版”

[英]C# XAML Universal Apps get rid of 'Mask' over TextBoxes

我有一个像这样的TextBox

<TextBox Background="#2196F3" Foreground="White" Text="Hello"/>

但随后, TextBox的背景不会变成'#2196F3'-它变成了阴影变浅,因为Universal App TextBox的上方有这个灰色的“蒙版”。

带“遮罩”的TextBox -不专心
在此处输入图片说明

为了解决这个问题,我在文本框后面放置了一个网格并使文本框透明。

带网格的TextBox -不专心 文字框-不专心

但是当我集中精力时 在此处输入图片说明

Windows应用商店设法删除了“掩码”,但我不知道如何...

那么,如何使TextBox保持“#2196F3”,即使它已被聚焦? 提前致谢。

您将需要自定义文本框的模板。 为TextBox创建一种新样式,并将其应用于当前的TextBox。

Windows Store manages to remove the 'mask', but I don't know how...

这是因为当您对TextBox进行聚焦时, 默认模板中存在用于Focused状态的可视状态,这会更改TextBox的UI。

如何自定义TextBox的“焦点”样式,使其在聚焦状态下不会变得不透明或蒙版不存在或什至有可能

正如@ thang2410199所说,您需要修改TextBox的模板以实现您的要求。

有关详细步骤,请检查以下信息:

1.请右键单击TextBox控件->“编辑模板”->“编辑副本...”,然后它将显示TextBox控件的默认样式。

在此处输入图片说明

2.之后,请以TextBox控件的默认样式找到以下xaml:

                   <VisualState x:Name="Focused">
                                 <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocusedOpacity}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="RequestedTheme" Storyboard.TargetName="ContentElement">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Light"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>

3.删除/删除上述Focused XAML中的以下xaml,以在TextBox处于Focused状态时使TextBox保持为“#2196F3”:

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}"/>
</ObjectAnimationUsingKeyFrames>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM