![](/img/trans.png)
[英]C# XAML Universal Apps - Change StackPanel's width as TextBoxes inside grow
[英]C# XAML Universal Apps get rid of 'Mask' over TextBoxes
我有一个像这样的TextBox
:
<TextBox Background="#2196F3" Foreground="White" Text="Hello"/>
但随后, TextBox
的背景不会变成'#2196F3'-它变成了阴影变浅,因为Universal App 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.