这次私人定制的是背景透明的TextBox,普通的TextBox在获取焦点后,背景色就变白色了。

下面的代码可以让TextBox的背景始终是透明的。

其实很简单,就修改了

  1. <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />
  2. 改为
  3. <Setter Property="Background" Value="Transparent" />
  4. <VisualState x:Name="Focused">下面的
  5. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
  6. Storyboard.TargetProperty="Background">
  7. <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
  8. </ObjectAnimationUsingKeyFrames>

看效果:

  1. <Style x:Key="TransparentBackgroundTextBoxStyle" TargetType="TextBox">
  2. <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
  3. <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
  4. <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
  5. <Setter Property="Background" Value="Transparent" />
  6. <!--<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />-->
  7. <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" />
  8. <Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
  9. <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
  10. <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
  11. <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
  12. <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto" />
  13. <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
  14. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
  15. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
  16. <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
  17. <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/>
  18. <Setter Property="Template">
  19. <Setter.Value>
  20. <ControlTemplate TargetType="TextBox">
  21. <Grid>
  22. <Grid.Resources>
  23. <Style x:Name="DeleteButtonStyle" TargetType="Button">
  24. <Setter Property="Template">
  25. <Setter.Value>
  26. <ControlTemplate TargetType="Button">
  27. <Grid x:Name="ButtonLayoutGrid" BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}"
  28. BorderThickness="{TemplateBinding BorderThickness}"
  29. Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}">
  30. <VisualStateManager.VisualStateGroups>
  31. <VisualStateGroup x:Name="CommonStates">
  32. <VisualState x:Name="Normal" />
  33. <VisualState x:Name="PointerOver">
  34. <Storyboard>
  35. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
  36. Storyboard.TargetProperty="Foreground">
  37. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
  38. </ObjectAnimationUsingKeyFrames>
  39. </Storyboard>
  40. </VisualState>
  41. <VisualState x:Name="Pressed">
  42. <Storyboard>
  43. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid"
  44. Storyboard.TargetProperty="Background">
  45. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
  46. </ObjectAnimationUsingKeyFrames>
  47. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
  48. Storyboard.TargetProperty="Foreground">
  49. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" />
  50. </ObjectAnimationUsingKeyFrames>
  51. </Storyboard>
  52. </VisualState>
  53. <VisualState x:Name="Disabled">
  54. <Storyboard>
  55. <DoubleAnimation Storyboard.TargetName="ButtonLayoutGrid"
  56. Storyboard.TargetProperty="Opacity"
  57. To="0"
  58. Duration="0" />
  59. </Storyboard>
  60. </VisualState>
  61. </VisualStateGroup>
  62. </VisualStateManager.VisualStateGroups>
  63. <TextBlock x:Name="GlyphElement"
  64. Foreground="{ThemeResource SystemControlForegroundChromeBlackMediumBrush}"
  65. VerticalAlignment="Center"
  66. HorizontalAlignment="Center"
  67. FontStyle="Normal"
  68. FontSize="12"
  69. Text=""
  70. FontFamily="{ThemeResource SymbolThemeFontFamily}"
  71. AutomationProperties.AccessibilityView="Raw"/>
  72. </Grid>
  73. </ControlTemplate>
  74. </Setter.Value>
  75. </Setter>
  76. </Style>
  77. </Grid.Resources>
  78. <VisualStateManager.VisualStateGroups>
  79. <VisualStateGroup x:Name="CommonStates">
  80. <VisualState x:Name="Disabled">
  81. <Storyboard>
  82. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter"
  83. Storyboard.TargetProperty="Foreground">
  84. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" />
  85. </ObjectAnimationUsingKeyFrames>
  86. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
  87. Storyboard.TargetProperty="Background">
  88. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}" />
  89. </ObjectAnimationUsingKeyFrames>
  90. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
  91. Storyboard.TargetProperty="Background">
  92. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
  93. </ObjectAnimationUsingKeyFrames>
  94. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
  95. Storyboard.TargetProperty="BorderBrush">
  96. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
  97. </ObjectAnimationUsingKeyFrames>
  98. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
  99. Storyboard.TargetProperty="Foreground">
  100. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
  101. </ObjectAnimationUsingKeyFrames>
  102. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter"
  103. Storyboard.TargetProperty="Foreground">
  104. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
  105. </ObjectAnimationUsingKeyFrames>
  106. </Storyboard>
  107. </VisualState>
  108. <VisualState x:Name="Normal" />
  109. <VisualState x:Name="PointerOver">
  110. <Storyboard>
  111. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
  112. Storyboard.TargetProperty="BorderBrush">
  113. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightChromeAltLowBrush}" />
  114. </ObjectAnimationUsingKeyFrames>
  115. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
  116. Storyboard.TargetProperty="Opacity">
  117. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" />
  118. </ObjectAnimationUsingKeyFrames>
  119. </Storyboard>
  120. </VisualState>
  121. <VisualState x:Name="Focused">
  122. <Storyboard>
  123. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter"
  124. Storyboard.TargetProperty="Foreground">
  125. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" />
  126. </ObjectAnimationUsingKeyFrames>
  127. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
  128. Storyboard.TargetProperty="Background">
  129. <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
  130. </ObjectAnimationUsingKeyFrames>
  131. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement"
  132. Storyboard.TargetProperty="Opacity">
  133. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocusedOpacity}" />
  134. </ObjectAnimationUsingKeyFrames>
  135. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement"
  136. Storyboard.TargetProperty="BorderBrush">
  137. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
  138. </ObjectAnimationUsingKeyFrames>
  139. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
  140. Storyboard.TargetProperty="Foreground">
  141. <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" />
  142. </ObjectAnimationUsingKeyFrames>
  143. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement"
  144. Storyboard.TargetProperty="RequestedTheme">
  145. <DiscreteObjectKeyFrame KeyTime="0" Value="Light" />
  146. </ObjectAnimationUsingKeyFrames>
  147. </Storyboard>
  148. </VisualState>
  149. </VisualStateGroup>
  150. <VisualStateGroup x:Name="ButtonStates">
  151. <VisualState x:Name="ButtonVisible">
  152. <Storyboard>
  153. <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton"
  154. Storyboard.TargetProperty="Visibility">
  155. <DiscreteObjectKeyFrame KeyTime="0">
  156. <DiscreteObjectKeyFrame.Value>
  157. <Visibility>Visible</Visibility>
  158. </DiscreteObjectKeyFrame.Value>
  159. </DiscreteObjectKeyFrame>
  160. </ObjectAnimationUsingKeyFrames>
  161. </Storyboard>
  162. </VisualState>
  163. <VisualState x:Name="ButtonCollapsed" />
  164. </VisualStateGroup>
  165. </VisualStateManager.VisualStateGroups>
  166. <Grid.ColumnDefinitions>
  167. <ColumnDefinition Width="*" />
  168. <ColumnDefinition Width="Auto" />
  169. </Grid.ColumnDefinitions>
  170. <Grid.RowDefinitions>
  171. <RowDefinition Height="Auto" />
  172. <RowDefinition Height="*" />
  173. </Grid.RowDefinitions>
  174. <Border x:Name="BackgroundElement"
  175. Grid.Row="1"
  176. Background="{TemplateBinding Background}"
  177. Margin="{TemplateBinding BorderThickness}"
  178. Opacity="{ThemeResource TextControlBackgroundRestOpacity}"
  179. Grid.ColumnSpan="2"
  180. Grid.RowSpan="1"/>
  181. <Border x:Name="BorderElement"
  182. Grid.Row="1"
  183. BorderBrush="{TemplateBinding BorderBrush}"
  184. BorderThickness="{TemplateBinding BorderThickness}"
  185. Grid.ColumnSpan="2"
  186. Grid.RowSpan="1"/>
  187. <ContentPresenter x:Name="HeaderContentPresenter"
  188. x:DeferLoadStrategy="Lazy"
  189. Visibility="Collapsed"
  190. Grid.Row="0"
  191. Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
  192. Margin="0,0,0,8"
  193. Grid.ColumnSpan="2"
  194. Content="{TemplateBinding Header}"
  195. ContentTemplate="{TemplateBinding HeaderTemplate}"
  196. FontWeight="Normal" />
  197. <ScrollViewer x:Name="ContentElement"
  198. Grid.Row="1"
  199. HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
  200. HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
  201. VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
  202. VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
  203. IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
  204. IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
  205. IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
  206. Margin="{TemplateBinding BorderThickness}"
  207. Padding="{TemplateBinding Padding}"
  208. IsTabStop="False"
  209. AutomationProperties.AccessibilityView="Raw"
  210. ZoomMode="Disabled" />
  211. <ContentControl x:Name="PlaceholderTextContentPresenter"
  212. Grid.Row="1"
  213. Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
  214. Margin="{TemplateBinding BorderThickness}"
  215. Padding="{TemplateBinding Padding}"
  216. IsTabStop="False"
  217. Grid.ColumnSpan="2"
  218. Content="{TemplateBinding PlaceholderText}"
  219. IsHitTestVisible="False"/>
  220. <Button x:Name="DeleteButton"
  221. Grid.Row="1"
  222. Style="{StaticResource DeleteButtonStyle}"
  223. BorderThickness="{TemplateBinding BorderThickness}"
  224. Margin="{ThemeResource HelperButtonThemePadding}"
  225. IsTabStop="False"
  226. Grid.Column="1"
  227. Visibility="Collapsed"
  228. FontSize="{TemplateBinding FontSize}"
  229. MinWidth="34"
  230. VerticalAlignment="Stretch"/>
  231. </Grid>
  232. </ControlTemplate>
  233. </Setter.Value>
  234. </Setter>
  235. </Style>
  1. TextBox原型 https://msdn.microsoft.com/en-us/library/windows/apps/mt299154.aspx?f=255&MSPPError=-2147217396
    各位用的时候不要太死板,按需修改即可。

UWP TextBox私人定制的更多相关文章

  1. UWP 滚动条私人定制

    最近突然发现微软自带的滚动条好挫哦 微软哒(棒棒哒) 网上找的(美美哒) 好了. 如果你想要棒棒哒,那么就不用往下看了(手动再见). 如果你想要美美哒,就需要下面的神秘代码. <Style Ta ...

  2. 私人定制自己的linux小系统

     私人定制自己的linux小系统 一.前言    linux操作系统至1991.10.5号诞生以来,就源其开源性和自由性得到了很多技术大牛的青睐,每个linux爱好者都为其贡献了自己的一份力,不管是在 ...

  3. 高级私人定制西服品牌:XUAN PRIVE 为定制而生_乐活_onlylady女人志

    高级私人定制西服品牌:XUAN PRIVE 为定制而生_乐活_onlylady女人志 高级私人定制西服品牌:XUAN PRIVE 为定制而生

  4. OSX: 私人定制Dock默认程序图标

    不论什么一个新用户第一次登陆后,OSX都会自己主动地在用户的Dock中列出系统默认的应用程序图标,这些图标随着OSX版本号的不同而不同. 系统管理员有的时候须要改变这些系统默认图标,或者加入自己的或者 ...

  5. 去英国Savile Row 做件私人定制手工西装_GQ男士网

    去英国Savile Row 做件私人定制手工西装_GQ男士网 去英国Savile Row 做件私人定制手工西装

  6. 绫致时装讲述O2O细节:野心在“私人定制” - 移动购物 - 亿邦动力网

    绫致时装讲述O2O细节:野心在"私人定制" - 移动购物 - 亿邦动力网 绫致时装讲述O2O细节:野心在"私人定制" 作者: 亿邦动力网来源: 亿邦动力网201 ...

  7. 私人定制javascript事件处理机制(浅谈)

    看到园子里关于事件监听发表的文章,我都有点不好意思写了.不过想想我的题目以私人定制作开头也就妥妥地写吧. 事件相关概念 1.事件类型 发生事件的字符串 有传统事件类型 比如表单.window事件等 D ...

  8. 旅行app(游记、攻略、私人定制) | 顺便游旅行H5移动端实例

    <顺便游旅行>是一款H5移动端旅行app,提供目的地(国内.国外.周边)搜索.旅游攻略查询.游记分享.私人定制4大模块,类似携程.同程.去哪儿.马蜂窝移动端,只不过顺便游app界面更为简洁 ...

  9. JWinner:一个私人定制的快速开发框架,为理想而生

    关于JWinner JWinner是一个JAVA项目的快速开发框架,他已经实现了大多数项目开发之前需要进行的一些必备工作,还有很多在开发过程中可能会用到的工具集. JWinner的诞生并不是一蹴而就的 ...

随机推荐

  1. 多线程编程 - PHP 实现

    * { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...

  2. 【Mysql知识补充】

    一.子查询 1.定义 子查询是将一个查询语句嵌套在另一个查询语句中.内层查询语句的查询结果,可以为外层查询语句提供查询条件.子查询中可以包含:IN.NOT IN.ANY.ALL.EXISTS 和 NO ...

  3. c语言贪吃蛇详解1.画出地图

    c语言贪吃蛇详解-1.画出地图 前几天的实验室培训课后作业我布置了贪吃蛇,今天有时间就来写一下题解.我将分几步来教大家写一个贪吃蛇小游戏.由于大家c语言未学完,这个教程只涉及数组和函数等知识点. 首先 ...

  4. C#爬虫系列(二)——食品安全国家标准数据检索平台

    上篇对“国家标准全文公开系统”的国标进行抓取,本篇对食品领域的标准公开系统“食品安全国家标准数据检索平台”进行抓取. 平台地址:http://bz.cfsa.net.cn/db 一.标准列表 第一步还 ...

  5. hdu 1496 Equations hash表

    hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...

  6. CCF-201509-3-生成模板系统

    问题描述 试题编号: 201509-3 试题名称: 模板生成系统 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 成成最近在搭建一个网站,其中一些页面的部分内容来自数据库中不同 ...

  7. 五.Spring与RabbitMQ集成--HelloWorld

    spring对RabbitMQ做了很好的集成,我们称之为spring AMQP,其官方文档写得十分详尽,文档地址:https://docs.spring.io/spring-amqp/referenc ...

  8. ConcurrentModificationException异常出现的原因

    原因:对list .map 等迭代的时进行修改就会抛出java.util.ConcurrentModificationException异常 比如: public synchronized void ...

  9. MyEclipse激活步骤

    1.前言:   MyEclipse 成功安装后使用天数仅仅有30天,打开软件后常常会弹出提醒我们在5天内要激活的对话框.没有激活的话,时间一到就不能使用了. 众所周知,中国的软件是不用花钱的,这里就介 ...

  10. JQuery学习(4-2-phpserver端1)

    主要内容:介绍图片的上传过程,涉及PHP跟JQuery: 1. 读取配置文件,连接MySQL数据库. 配置文件主要实username和password. 3-5.php <?php /* * v ...