定义Windows Phone中PhoneTextBox的样式

2024-01-26

我正在重写 PhoneTextBox 的样式,将默认背景更改为“透明”,将前景更改为“白色”,将 BorderBrush 更改为“白色”,因为我想设计一个深色主题。

但是出现了一个问题,文本输入指示器消失了。我感谢原因是文本输入指示器的前景是黑色的,所以用户看不到它。但我找不到定义文本输入指示器的前景的方法。任何提示都会被应用。

附言。我不知道如何描述该指标,我是否自己编了一个“text-input-indicator”这个词,如下所示:

正常情况下,会出现黑色竖线。

重写样式后,用户看不到黑色竖线:

和xaml代码:

 <Style x:Key="PhoneTextBoxStyle" TargetType="toolkit:PhoneTextBox">
        <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="BorderBrush" Value="White"/>
        <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/>
        <Setter Property="SelectionForeground" Value="White"/>
        <Setter Property="BorderThickness" Value="2"/>
        <Setter Property="Padding" Value="{StaticResource PhoneBorderThickness}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="toolkit:PhoneTextBox">
                    <Grid x:Name="RootGrid" Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Disabled">
                                </VisualState>
                                <VisualState x:Name="Enabled">
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                </VisualState>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="LengthIndicatorStates">
                                <VisualState x:Name="LengthIndicatorVisible">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="LengthIndicator">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="RootGrid">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0, 0, 0, 27"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="LengthIndicator">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0.6"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Duration="0:0:0.350" To="32" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Storyboard.TargetName="LengthIndicator">
                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase Exponent="6"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="LengthIndicatorHidden">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.350" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Storyboard.TargetName="LengthIndicator">
                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase Exponent="6"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="RootGrid">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0, 0, 0, 0"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="LengthIndicator">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.350" Value="0"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="LengthIndicator">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.350">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="LengthIndicatorBorder">
                            <TextBlock x:Name="LengthIndicator" Foreground="{StaticResource PhoneContrastBackgroundBrush}" FontSize="{StaticResource PhoneFontSizeNormal}" HorizontalAlignment="Right" Margin="0" Opacity="0" TextAlignment="Right" VerticalAlignment="Bottom">
                                    <TextBlock.RenderTransform>
                                        <TranslateTransform/>
                                    </TextBlock.RenderTransform>
                            </TextBlock>
                        </Border>
                        <Border x:Name="HintBorder" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="{TemplateBinding Background}" Margin="0">
                            <Grid>
                                <ContentControl x:Name="HintContent" Background="Transparent" Content="{TemplateBinding Hint}"
                                                HorizontalAlignment="Left" Margin="3,5,3,0" Style="{TemplateBinding HintStyle}" 
                                                Foreground="Gray"
                                                Visibility="{TemplateBinding ActualHintVisibility}" VerticalAlignment="Top"/>
                                <ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" 
                                                Margin="{StaticResource PhoneTextBoxInnerMargin}" 
                                                Padding="{TemplateBinding Padding}"
                                                VerticalContentAlignment="Stretch"/>
                            </Grid>
                        </Border>
                        <Border x:Name="TextBorder" BorderBrush="White" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="Transparent" Margin="0" Visibility="Collapsed">
                            <TextBox x:Name="Text" Foreground="White" 
                                     FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" 
                                     FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}"
                                     HorizontalAlignment="Left" SelectionForeground="{TemplateBinding SelectionForeground}" 
                                     SelectionBackground="{TemplateBinding SelectionBackground}" 
                                     TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" 
                                     Text="{TemplateBinding Text}"/>
                        </Border>
                        <Border x:Name="ActionIconBorder" Background="Transparent" HorizontalAlignment="Right" Height="54" VerticalAlignment="Bottom" Width="54">
                            <Image x:Name="ActionIcon" Height="54" Source="{TemplateBinding ActionIcon}" Width="54"/>
                        </Border>
                        <TextBlock x:Name="MeasurementTextBlock" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" IsHitTestVisible="False" Margin="8" Opacity="0" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" Text="{TemplateBinding Text}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

可能您正在寻找CaretBrush, SelectionBackground and SelectionForeground。我不知道这些属性是否已绑定toolkit:PhoneTextBox,但无论如何你绝对可以手动重新设计它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

定义Windows Phone中PhoneTextBox的样式 的相关文章

随机推荐

  • 如何在Excel VBA中添加到当前单元格选择

    因此 我有一个循环检查列中的每个单元格并找到特定日期 当前是前一周的星期一 我的代码现在确实正确选择了它们 但我希望它保留之前的选择 以便最终选择该规范的所有单元格 Public Function LastMonday pdat As Da
  • 在 setup.py 中添加自定义轮文件作为依赖项?

    我正在开发一个项目 其中一个依赖项实际上是 whl这不在 pypi 上 即我必须直接从作者那里下载轮子并且pip直接安装 在我的setup py文件 有没有办法做类似的事情 install requires library whl matp
  • 如果检测到越界,则禁用平移手势

    我有一个 UIView 我试图在屏幕上上下移动 但是我只想让它平移 这样当视图处于正常位置 0 0 时 您就无法向下拖动视图 我尝试检测识别器的中心何时不是视图高度的一半 但是视图是不可移动的 并且中心始终是高度的一半 在本例中为 230
  • SQL 代理命令行未保存

    我有一个 SSIS 包 我正在尝试安排时间 我在 SQL Server 代理下创建了一个新作业 在作业步骤的 命令行 选项卡上 我选择 手动编辑命令行 当我在作业步骤中从一个选项卡切换到另一个选项卡时 更改会被保留 但每当我退出并保存作业时
  • 在 Ruby 中编写一个在不同行获取参数的方法

    在使用 Rails 时 我发现可以调用这样的方法 lot Lot new do u u grade id grade id u company id company id u type id type id u sale id sale i
  • 如何从 AsyncTask 返回布尔值?

    我有一些 EditText 用户输入 ftp 地址 用户名 密码 端口和 testConnection 按钮 如果连接成功建立 它将返回布尔值 true boolean status ftpConnect address username
  • 在eclipse中创建android项目时出错

    我是 Android 开发人员的新手 我正在学习 但是当我创建一个新项目时 显示了这个错误 在错误日志中我有很多错误 我不知道如何在这里导出所有错误 在项目资源管理器中 我的项目显示如下 我不知道如何解决所有这些错误 感谢您的帮助 并对我的
  • rspec测试协会

    我想在我的 rspec 控制器测试中测试员工是否与公司关联 我想在我的create工作人员财务主任的行动 staff companies lt lt current company Where current company从会话变量中收集
  • Flutter - 仅当内容高度大于屏幕高度时才启用滚动

    默认情况下 我在主体小部件中采用 ListView 或 SingleChildScrollView 因此 如果内容较少 则会滚动内容 我只想在内容大于屏幕高度时启用滚动 如果内容高度小于屏幕高度 需要禁用滚动 double physical
  • 镜头和类型系列

    我遇到了使用问题Control Lens和 一起使用时的数据类型 XTypeFamiliesGHC 杂注 LANGUAGE TemplateHaskell LANGUAGE TypeFamilies import Control Lens
  • 当 Android 中的软键盘出现在视图前面时,布局应该向上

    我有一个问题 我有一个登录屏幕 当我们单击编辑文本时 软输入键盘会覆盖两个小部件 一个是 TextView 另一个是登录按钮 它们位于相对布局中 但我希望当我们选择任何编辑文本时整个相对布局应该向上 并且所有小部件都在 Android 默认
  • 向 TextView 添加底线边框 - iOS

    添加底线边框的最佳方法是什么TextView具有动态高度 我试过这个 func addBottomBorderWithColor color UIColor width CGFloat let border CALayer border b
  • 如何获取 $date + 5 来排除周末?

    我有一些页面需要设置将来的日期 由变量设置的 2 天或 5 天 该日期只需计算周一至周五 不包括周末 到目前为止我所拥有的 tts 是 2 或 5 的变量 具体取决于页面 Today date N m y NewDate date l t
  • 在 Cassandra 列中存储 JSON 字符串的有效方法?

    卡桑德拉新手问题 我正在使用 REST 调用从社交网站收集一些数据 所以我最终得到了 JSON 格式的数据 JSON 只是我表中的列之一 我试图找出存储 JSON 字符串的 最佳实践 首先我想到使用map类型 但 JSON 包含字符串 数字
  • 如何阻止 while 循环无限运行?

    不知道如何阻止这个 while 循环无限重复 我在用着hasNextInt检查用户输入是否为 int 如果未输入 int 则循环将无限重复 public static void validatingInput Scanner scan ne
  • 选择另一个表中不存在的值

    我有两张桌子 Table A ID 1 2 3 4 Table B ID 1 2 3 我有两个请求 我想选择表 A 中表 B 没有的所有行 在本例中是第 4 行 我想删除表 B 中没有的所有行 我正在使用 SQL Server 2000 你
  • Sonar:复制/高可用性或集群解决方案

    SonarQube Sonar 是否支持复制 高可用性解决方案 我的目标是在当前实例运行的计算机上出现硬件故障时拥有一个故障转移 SonarQube 实例 目前不支持 SonarQube 集群 目前您能做的只是准备好虚拟机 以便在 Sona
  • 如何对数据表中的列进行排序。 JSF 2.0

    我正在 jsf 2 0 中构建一个 WebApp 它用于存储信息并将其显示在屏幕上 所以我放入了一些 http java sun com jsf html 数据表来显示一些列表 我的 Java 代码返回一个列表 然后将它们显示在屏幕上 但现
  • 从 SSIS 目录执行包时无法访问网络共享

    我目前遇到一个问题 我可以从 SQL Server Data Tools 完美地执行包 但在尝试从 SSIS 目录中执行时出现以下错误 文件系统任务 错误 发生错误 并显示以下错误消息 访问路径 xxxxxxxx xxxx 被拒绝 我使用相
  • 定义Windows Phone中PhoneTextBox的样式

    我正在重写 PhoneTextBox 的样式 将默认背景更改为 透明 将前景更改为 白色 将 BorderBrush 更改为 白色 因为我想设计一个深色主题 但是出现了一个问题 文本输入指示器消失了 我感谢原因是文本输入指示器的前景是黑色的