[源码下载]

重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性

作者:webabcd

介绍
重新想象 Windows 8.1 Store Apps 之控件增强

  • 文本类控件的增强
  • 为一些控件增加了 Header 属性和 HeaderTemplate 属性
  • 为一些控件增加了 PlaceholderText 属性

示例
1、演示文本类控件的新增功能
TextDemo.xaml

  1. <Page
  2. x:Class="Windows81.Controls.TextDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows81.Controls"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="Transparent">
  11. <StackPanel Margin="120 0 0 0">
  12.  
  13. <!--文本显示类控件新增了 MaxLines 属性:用于指定文本最大的显示行数-->
  14. <TextBlock FontSize="14.667" MaxLines="3">
  15. <TextBlock.Inlines>
  16. <Run>111111</Run>
  17. <LineBreak />
  18. <Run>222222</Run>
  19. <LineBreak />
  20. <Run>333333</Run>
  21. <LineBreak />
  22. <Run>444444</Run>
  23. <LineBreak />
  24. <Run>555555</Run>
  25. <LineBreak />
  26. <Run>666666</Run>
  27. </TextBlock.Inlines>
  28. </TextBlock>
  29.  
  30. <!--文本输入类控件新增了 PreventKeyboardDisplayOnProgrammaticFocus 属性:当通过编程方式在文本框上设置焦点时,是否不显示屏幕触摸键盘-->
  31. <TextBox Margin="0 10 10 0" PreventKeyboardDisplayOnProgrammaticFocus="True" />
  32.  
  33. <!--
  34. 文本显示类控件和文本输入类控件:
  35. IsTextSelectionEnabled - 用于指定文本是否可以选中
  36. SelectionHighlightColor - 用于指定选中文本的颜色
  37. -->
  38. <TextBlock Text="webabcd" FontSize="14.667" Margin="0 10 0 0" IsTextSelectionEnabled="True">
  39. <TextBlock.SelectionHighlightColor>
  40. <SolidColorBrush Color="Red" />
  41. </TextBlock.SelectionHighlightColor>
  42. </TextBlock>
  43.  
  44. <!--文本输入类控件新增了 Paste 事件-->
  45. <TextBox Name="txtPaste" PlaceholderText="自定义粘贴文本数据" Paste="txtPaste_Paste" Margin="0 10 0 0" />
  46.  
  47. <!--
  48. 文本显示类控件
  49. TextTrimming.None - 不修整文本
  50. TextTrimming.Clip - 在像素级别修整文本(win8.1 新增)
  51. TextTrimming.WordEllipsis - 在单词级别修整文本,同时用省略号代替剩余文本
  52. TextTrimming.CharacterEllipsis - 在字符级别修整文本,同时用省略号代替剩余文本(win8.1 新增)
  53. -->
  54. <TextBlock FontSize="24" HorizontalAlignment="Left" Text="abcdefghijklmnopqrstuvwxyz" Width="200" Margin="0 10 0 0" TextTrimming="None"/>
  55. <TextBlock FontSize="24" HorizontalAlignment="Left" Text="abcdefghijklmnopqrstuvwxyz" Width="200" Margin="0 10 0 0" TextTrimming="Clip"/>
  56. <TextBlock FontSize="24" HorizontalAlignment="Left" Text="abcdef ghijklm nopqrstuvwxyz" Width="200" Margin="0 10 0 0" TextTrimming="WordEllipsis"/>
  57. <TextBlock FontSize="24" HorizontalAlignment="Left" Text="abcdef ghijklm nopqrstuvwxyz" Width="200" Margin="0 10 0 0" TextTrimming="CharacterEllipsis"/>
  58.  
  59. <!--
  60. 新增的 TextWrapping.WrapWholeWords 仅针对文本显示类控件:
  61. TextWrapping.NoWrap - 不换行(文本显示类控件和文本输入类控件可用)
  62. TextWrapping.Wrap - 换行,必要时可截断单词(文本显示类控件和文本输入类控件)
  63. TextWrapping.WrapWholeWords - 换行,但是绝不截断单词,即使单词可能会显示不全(仅针对文本显示类控件,win8.1 新增)
  64. -->
  65. <TextBlock FontSize="24.667" HorizontalAlignment="Left" Width="100" Height="60" Text="iamwebabcd w" Margin="0 10 0 0" TextWrapping="NoWrap" />
  66. <TextBlock FontSize="24.667" HorizontalAlignment="Left" Width="100" Height="60" Text="iamwebabcd w" Margin="0 10 0 0" TextWrapping="Wrap" />
  67. <TextBlock FontSize="24.667" HorizontalAlignment="Left" Width="100" Height="60" Text="iamwebabcd w" Margin="0 10 0 0" TextWrapping="WrapWholeWords" />
  68.  
  69. </StackPanel>
  70. </Grid>
  71. </Page>

TextDemo.xaml.cs

  1. /*
  2. * 本例演示文本类控件的新增功能
  3. *
  4. *
  5. * 关于文本类控件的基础请参见:
  6. * http://www.cnblogs.com/webabcd/archive/2013/01/07/2848564.html
  7. */
  8.  
  9. using System;
  10. using Windows.ApplicationModel.DataTransfer;
  11. using Windows.UI.Xaml.Controls;
  12.  
  13. namespace Windows81.Controls
  14. {
  15. public sealed partial class TextDemo : Page
  16. {
  17. public TextDemo()
  18. {
  19. this.InitializeComponent();
  20. }
  21.  
  22. // 当在一个文本输入类控件中粘贴时触发的事件
  23. private async void txtPaste_Paste(object sender, TextControlPasteEventArgs e)
  24. {
  25. // 关于剪切板的基础请参见:http://www.cnblogs.com/webabcd/archive/2013/07/08/3177123.html
  26.  
  27. DataPackageView dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
  28.  
  29. // 判断剪切板中是否有文本数据
  30. if (dataPackageView.Contains(StandardDataFormats.Text))
  31. {
  32. try
  33. {
  34. // 获取剪切板中的文本数据
  35. string text = await dataPackageView.GetTextAsync();
  36.  
  37. // 用我们自定义的方式粘贴数据
  38. txtPaste.Text = text + text;
  39. }
  40. catch
  41. {
  42.  
  43. }
  44. }
  45. else
  46. {
  47.  
  48. }
  49.  
  50. // 已经处理粘贴操作了,其他路由不用再处理了
  51. e.Handled = true;
  52. }
  53. }
  54. }

2、控件 ComboBox, Slider, DatePicker, TimePicker, TextBox, PasswordBox, RichEditBox 增加了 Header 属性和 HeaderTemplate 属性
ControlHeader.xaml

  1. <Page
  2. x:Class="Windows81.Controls.ControlHeader"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows81.Controls"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="Transparent">
  11. <StackPanel Margin="120 0 0 0">
  12.  
  13. <!--
  14. 控件 ComboBox, Slider, DatePicker, TimePicker, TextBox, PasswordBox, RichEditBox
  15. 增加了 Header 属性和 HeaderTemplate 属性
  16. -->
  17.  
  18. <!--
  19. 设置 TextBox 的 HeaderTemplate
  20. -->
  21. <TextBox Name="textBox" IsReadOnly="True" Margin="0 0 20 0">
  22. <TextBox.HeaderTemplate>
  23. <DataTemplate>
  24. <Button Content="Click to edit" Click="Button_Click" />
  25. </DataTemplate>
  26. </TextBox.HeaderTemplate>
  27. </TextBox>
  28.  
  29. </StackPanel>
  30. </Grid>
  31. </Page>

ControlHeader.xaml.cs

  1. /*
  2. * 控件 ComboBox, Slider, DatePicker, TimePicker, TextBox, PasswordBox, RichEditBox 增加了 Header 属性和 HeaderTemplate 属性
  3. * 1、Header - 可以设置一个纯文本,不能命中测试,空 Header 的话不会占用任何空间
  4. * 2、HeaderTemplate - 可以将 Header 设置为任何 xaml,且支持命中测试
  5. */
  6.  
  7. using Windows.UI.Xaml;
  8. using Windows.UI.Xaml.Controls;
  9.  
  10. namespace Windows81.Controls
  11. {
  12. public sealed partial class ControlHeader : Page
  13. {
  14. public ControlHeader()
  15. {
  16. this.InitializeComponent();
  17. }
  18.  
  19. private void Button_Click(object sender, RoutedEventArgs e)
  20. {
  21. textBox.IsReadOnly = false;
  22.  
  23. // 设置 TextBox 的 HeaderTemplate 和 Header
  24. textBox.HeaderTemplate = null;
  25. textBox.Header = "Editable TextBox";
  26. }
  27. }
  28. }

3、控件 ComboBox, PasswordBox, RichEditBox, SearchBox, TextBox 增加了 PlaceholderText 属性
PlaceholderTextDemo.xaml

  1. <Page
  2. x:Class="Windows81.Controls.PlaceholderTextDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows81.Controls"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="Transparent">
  11. <StackPanel Margin="120 0 0 0">
  12.  
  13. <!--
  14. 控件 ComboBox, PasswordBox, RichEditBox, SearchBox, TextBox
  15. 增加了 PlaceholderText 属性
  16. -->
  17.  
  18. <!--
  19. 设置 ComboBox 的 PlaceholderText
  20. -->
  21. <ComboBox Header="Colors" PlaceholderText="Pick a color" Margin="0 0 20 0">
  22. <x:String>Blue</x:String>
  23. <x:String>Green</x:String>
  24. <x:String>Red</x:String>
  25. <x:String>Yellow</x:String>
  26. </ComboBox>
  27.  
  28. <!--
  29. 设置 PasswordBox 的 PlaceholderText
  30. -->
  31. <PasswordBox Header="Password" PlaceholderText="Enter your password" Margin="0 20 20 0" />
  32.  
  33. </StackPanel>
  34. </Grid>
  35. </Page>

PlaceholderTextDemo.xaml.cs

  1. /*
  2. * 控件 ComboBox, PasswordBox, RichEditBox, SearchBox, TextBox 增加了 PlaceholderText 属性
  3. */
  4.  
  5. using Windows.UI.Xaml.Controls;
  6.  
  7. namespace Windows81.Controls
  8. {
  9. public sealed partial class PlaceholderTextDemo : Page
  10. {
  11. public PlaceholderTextDemo()
  12. {
  13. this.InitializeComponent();
  14. }
  15. }
  16. }

OK
[源码下载]

重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性的更多相关文章

  1. 重新想象 Windows 8.1 Store Apps 系列文章索引

    [源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  2. 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox

    [源码下载] 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 ...

  3. 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图

    [源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...

  4. 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar

    [源码下载] 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  5. 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker

    [源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...

  6. 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout

    [源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...

  7. 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink

    [源码下载] 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink 作者:webabcd 介绍重新想象 Windows 8.1 Store A ...

  8. 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup

    [源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...

  9. 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame

    [源码下载] 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame 作者:webabcd 介绍重新想象 Windows 8.1 St ...

随机推荐

  1. Swift:如何判断一个对象是否是某个类(或其子类)的实例

    在OC中我们直接可以用如下方法即可 [obj  isKindOfClass:[obj class]]; 在Swift中,并没有 .class 属性或者方法, 便可以用如下方法 class Person ...

  2. iOS常用宏 定义

    总结了iOS开发过程中的一些常用宏,以后会陆陆续续添加进来. 字符串是否为空 1   #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull c ...

  3. PHP 中 Orientation 属性判断上传图片是否需要旋转(转)

    <?php $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name'])); $ex ...

  4. CSS - Select 标签在不同浏览器中的高度设置

    当使用Select标签时,在不同浏览器中显示的高度不同,如何解决此问题: 解决方法链接:http://stackoverflow.com/questions/20477823/select-html- ...

  5. Ajax实现提交表单时验证码自动验证(原创自Zjmainstay)

    本文通过源码展示如何实现表单提交前,验证码先检测正确性,不正确则不提交表单,更新验证码. 1.前端代码 index.html <!DOCTYPE html> <html> &l ...

  6. java之final关键字

    final关键字(可以读不可以写.只读) 1.final的变量的值不能够被改变 ①.final的成员变量 ②.final的局部变量(形参) //意思是“实参”一旦传进我的方法里面,就不允许改变 2.f ...

  7. apache下virtualhost与location合用配置转发SVN控制访问

    使用apache的文件系统配置 使用virtualhost 实现location 重定向 NameVirtualHost *:80 <VirtualHost *:80> ServerNam ...

  8. 年底奉献-QT编写视频监管平台(开源)

    忙忙碌碌又是一年,算算自己毕业四年半,一直在现在这家公司做研发外加总经理助理,研发起初用的VB.NET,而后全面转为C#,最后又全面转为QT,都是由于项目需要,算下来自己搞QT编程也已经四年了,201 ...

  9. Mysql :removeAbandonedTimeout:180

    #数据库链接超过3分钟开始关闭空闲连接 秒为单位 removeAbandonedTimeout:180 这个参数会是一个坑吗? http://www.oschina.net/question/1867 ...

  10. c++ 相关的技术资源整理归类

    最近一段时间 c++ 社区里最火热的话题莫过于 cppcon2015 了, isocpp 上一堆相关的新闻,其中有一个页面罗列了该会议的全部主题, 匆匆一瞥几乎眼花缭乱,为期一个星期的会议竟有上百个演 ...