UWP TextBox私人定制
这次私人定制的是背景透明的TextBox,普通的TextBox在获取焦点后,背景色就变白色了。
下面的代码可以让TextBox的背景始终是透明的。
其实很简单,就修改了
- <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />
- 改为
- <Setter Property="Background" Value="Transparent" />
- <VisualState x:Name="Focused">下面的
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
- Storyboard.TargetProperty="Background">
- <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
- </ObjectAnimationUsingKeyFrames>
看效果:
- <Style x:Key="TransparentBackgroundTextBoxStyle" TargetType="TextBox">
- <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
- <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
- <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
- <Setter Property="Background" Value="Transparent" />
- <!--<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />-->
- <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" />
- <Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
- <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
- <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
- <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
- <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto" />
- <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
- <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 x:Name="ButtonLayoutGrid" BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}">
- <VisualStateManager.VisualStateGroups>
- <VisualStateGroup x:Name="CommonStates">
- <VisualState x:Name="Normal" />
- <VisualState x:Name="PointerOver">
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Pressed">
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid"
- Storyboard.TargetProperty="Background">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" />
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Disabled">
- <Storyboard>
- <DoubleAnimation Storyboard.TargetName="ButtonLayoutGrid"
- Storyboard.TargetProperty="Opacity"
- To="0"
- Duration="0" />
- </Storyboard>
- </VisualState>
- </VisualStateGroup>
- </VisualStateManager.VisualStateGroups>
- <TextBlock x:Name="GlyphElement"
- Foreground="{ThemeResource SystemControlForegroundChromeBlackMediumBrush}"
- VerticalAlignment="Center"
- HorizontalAlignment="Center"
- FontStyle="Normal"
- FontSize="12"
- Text=""
- FontFamily="{ThemeResource SymbolThemeFontFamily}"
- AutomationProperties.AccessibilityView="Raw"/>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </Grid.Resources>
- <VisualStateManager.VisualStateGroups>
- <VisualStateGroup x:Name="CommonStates">
- <VisualState x:Name="Disabled">
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
- Storyboard.TargetProperty="Background">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
- Storyboard.TargetProperty="Background">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
- Storyboard.TargetProperty="BorderBrush">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Normal" />
- <VisualState x:Name="PointerOver">
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
- Storyboard.TargetProperty="BorderBrush">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightChromeAltLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
- Storyboard.TargetProperty="Opacity">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" />
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="Focused">
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
- Storyboard.TargetProperty="Background">
- <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
- Storyboard.TargetProperty="Opacity">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocusedOpacity}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
- Storyboard.TargetProperty="BorderBrush">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
- Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" />
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
- Storyboard.TargetProperty="RequestedTheme">
- <DiscreteObjectKeyFrame KeyTime="0" Value="Light" />
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- </VisualStateGroup>
- <VisualStateGroup x:Name="ButtonStates">
- <VisualState x:Name="ButtonVisible">
- <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}"
- Opacity="{ThemeResource TextControlBackgroundRestOpacity}"
- 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"
- x:DeferLoadStrategy="Lazy"
- Visibility="Collapsed"
- Grid.Row="0"
- Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
- Margin="0,0,0,8"
- Grid.ColumnSpan="2"
- Content="{TemplateBinding Header}"
- ContentTemplate="{TemplateBinding HeaderTemplate}"
- FontWeight="Normal" />
- <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 SystemControlPageTextBaseMediumBrush}"
- Margin="{TemplateBinding BorderThickness}"
- Padding="{TemplateBinding Padding}"
- IsTabStop="False"
- Grid.ColumnSpan="2"
- Content="{TemplateBinding PlaceholderText}"
- IsHitTestVisible="False"/>
- <Button x:Name="DeleteButton"
- Grid.Row="1"
- Style="{StaticResource DeleteButtonStyle}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Margin="{ThemeResource HelperButtonThemePadding}"
- IsTabStop="False"
- Grid.Column="1"
- Visibility="Collapsed"
- FontSize="{TemplateBinding FontSize}"
- MinWidth="34"
- VerticalAlignment="Stretch"/>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- TextBox原型 https://msdn.microsoft.com/en-us/library/windows/apps/mt299154.aspx?f=255&MSPPError=-2147217396
各位用的时候不要太死板,按需修改即可。
UWP TextBox私人定制的更多相关文章
- UWP 滚动条私人定制
最近突然发现微软自带的滚动条好挫哦 微软哒(棒棒哒) 网上找的(美美哒) 好了. 如果你想要棒棒哒,那么就不用往下看了(手动再见). 如果你想要美美哒,就需要下面的神秘代码. <Style Ta ...
- 私人定制自己的linux小系统
私人定制自己的linux小系统 一.前言 linux操作系统至1991.10.5号诞生以来,就源其开源性和自由性得到了很多技术大牛的青睐,每个linux爱好者都为其贡献了自己的一份力,不管是在 ...
- 高级私人定制西服品牌:XUAN PRIVE 为定制而生_乐活_onlylady女人志
高级私人定制西服品牌:XUAN PRIVE 为定制而生_乐活_onlylady女人志 高级私人定制西服品牌:XUAN PRIVE 为定制而生
- OSX: 私人定制Dock默认程序图标
不论什么一个新用户第一次登陆后,OSX都会自己主动地在用户的Dock中列出系统默认的应用程序图标,这些图标随着OSX版本号的不同而不同. 系统管理员有的时候须要改变这些系统默认图标,或者加入自己的或者 ...
- 去英国Savile Row 做件私人定制手工西装_GQ男士网
去英国Savile Row 做件私人定制手工西装_GQ男士网 去英国Savile Row 做件私人定制手工西装
- 绫致时装讲述O2O细节:野心在“私人定制” - 移动购物 - 亿邦动力网
绫致时装讲述O2O细节:野心在"私人定制" - 移动购物 - 亿邦动力网 绫致时装讲述O2O细节:野心在"私人定制" 作者: 亿邦动力网来源: 亿邦动力网201 ...
- 私人定制javascript事件处理机制(浅谈)
看到园子里关于事件监听发表的文章,我都有点不好意思写了.不过想想我的题目以私人定制作开头也就妥妥地写吧. 事件相关概念 1.事件类型 发生事件的字符串 有传统事件类型 比如表单.window事件等 D ...
- 旅行app(游记、攻略、私人定制) | 顺便游旅行H5移动端实例
<顺便游旅行>是一款H5移动端旅行app,提供目的地(国内.国外.周边)搜索.旅游攻略查询.游记分享.私人定制4大模块,类似携程.同程.去哪儿.马蜂窝移动端,只不过顺便游app界面更为简洁 ...
- JWinner:一个私人定制的快速开发框架,为理想而生
关于JWinner JWinner是一个JAVA项目的快速开发框架,他已经实现了大多数项目开发之前需要进行的一些必备工作,还有很多在开发过程中可能会用到的工具集. JWinner的诞生并不是一蹴而就的 ...
随机推荐
- 多线程编程 - PHP 实现
* { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...
- 【Mysql知识补充】
一.子查询 1.定义 子查询是将一个查询语句嵌套在另一个查询语句中.内层查询语句的查询结果,可以为外层查询语句提供查询条件.子查询中可以包含:IN.NOT IN.ANY.ALL.EXISTS 和 NO ...
- c语言贪吃蛇详解1.画出地图
c语言贪吃蛇详解-1.画出地图 前几天的实验室培训课后作业我布置了贪吃蛇,今天有时间就来写一下题解.我将分几步来教大家写一个贪吃蛇小游戏.由于大家c语言未学完,这个教程只涉及数组和函数等知识点. 首先 ...
- C#爬虫系列(二)——食品安全国家标准数据检索平台
上篇对“国家标准全文公开系统”的国标进行抓取,本篇对食品领域的标准公开系统“食品安全国家标准数据检索平台”进行抓取. 平台地址:http://bz.cfsa.net.cn/db 一.标准列表 第一步还 ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- CCF-201509-3-生成模板系统
问题描述 试题编号: 201509-3 试题名称: 模板生成系统 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 成成最近在搭建一个网站,其中一些页面的部分内容来自数据库中不同 ...
- 五.Spring与RabbitMQ集成--HelloWorld
spring对RabbitMQ做了很好的集成,我们称之为spring AMQP,其官方文档写得十分详尽,文档地址:https://docs.spring.io/spring-amqp/referenc ...
- ConcurrentModificationException异常出现的原因
原因:对list .map 等迭代的时进行修改就会抛出java.util.ConcurrentModificationException异常 比如: public synchronized void ...
- MyEclipse激活步骤
1.前言: MyEclipse 成功安装后使用天数仅仅有30天,打开软件后常常会弹出提醒我们在5天内要激活的对话框.没有激活的话,时间一到就不能使用了. 众所周知,中国的软件是不用花钱的,这里就介 ...
- JQuery学习(4-2-phpserver端1)
主要内容:介绍图片的上传过程,涉及PHP跟JQuery: 1. 读取配置文件,连接MySQL数据库. 配置文件主要实username和password. 3-5.php <?php /* * v ...