Windows 8 Store Apps學習(1) 文本控制項

來源:互聯網
上載者:User

TextBlock, TextBox, PasswordBox, RichEd

介紹

重新想象 Windows 8 Store Apps 之文本控制項

TextBlock - 文本顯示框

TextBox - 文本輸入框

PasswordBox - 密碼輸入框

RichEditBox - 富文本編輯框

RichTextBlock - 富文本顯示框

RichTextBlockOverflow - 溢出文本顯示框

樣本

1、TextBlock 的 Demo

TextBlockDemo.xaml

<Page       x:Class="XamlDemo.Controls.TextBlockDemo"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:XamlDemo.Controls"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">              <Grid Background="Transparent">           <StackPanel Margin="120 0 0 0">                      <!--                   TextBlock 的常用屬性                   顯示的文本如果是引號等特殊字需要使用相應的 HTML 編碼               -->               <TextBlock Text="TextBlock &quot;的常用屬性&quot;" TextAlignment="Left" Foreground="Blue" FontFamily="微軟雅黑" FontSize="24" FontWeight="Bold" FontStyle="Italic" FontStretch="Normal" TextWrapping="Wrap" />                      <!--                   CharacterSpacing - 用於設定字元間距                       具體字元間隔像素計算公式如下:字型大小 * CharacterSpacing值 / 1000 = 字元間距像素值                   LineHeight - 行高                   LineStackingStrategy - 控制行高的策略                       MaxHeight - 每行的行高以 LineHeight 值和每行的自然行高中的最大值為準。預設值                       BlockLineHeight - 每行的行高以 LineHeight 值為準,以字元地區為參考                       BaselineToBaseline - 每行的行高以 LineHeight 值為準,以基準為參考(什麼是基準:英文字元的基準基本相當於單詞本4條線中的第3條線)                   Inlines - 內嵌元素的集合。包括 span, bold, italic, underline 等,但是 InlineUIContainer 不可用,其需要在 RichTextBlock 中使用               -->               <TextBlock FontSize="24" CharacterSpacing="100" LineStackingStrategy="MaxHeight" LineHeight="100">                   <TextBlock.Inlines>                       <Run Foreground="Red">Run</Run>                       <Span Foreground="Green">Span</Span>                       <LineBreak />                       <Bold>Bold</Bold>                       <Italic>Italic</Italic>                       <Underline>Underline</Underline>                   </TextBlock.Inlines>               </TextBlock>                      <!--                   TextTrimming - 文字溢出時的顯示方式                       TextTrimming.None - 不做任何處理                       TextTrimming.WordEllipsis - 在邊界處,用省略符號代替剩餘文本               -->               <TextBlock FontSize="24" HorizontalAlignment="Left" Text="abcdefghijklmnopqrstuvwxyz" Width="200" TextTrimming="WordEllipsis" />                      <!--                   FrameworkElement.FlowDirection - 指定文本或介面元素在它們的父元素中的流動方向                       FlowDirection.LeftToRight - 內容從左至右流動(預設值)                       FlowDirection.RightToLeft - 內容從右至左流動               -->               <TextBlock FontSize="24" HorizontalAlignment="Left" Text="abcdefg" Width="200" FlowDirection="RightToLeft" />                      <!--                   IsTextSelectionEnabled - 文本是否可以被選中               -->               <TextBlock FontSize="24" Name="lblSource" IsTextSelectionEnabled="True" SelectionChanged="txt_SelectionChanged_1">                   <TextBlock.Inlines>                       <Run>abcdefg</Run>                       <LineBreak />                       <Run>hijklmn</Run>                       <LineBreak />                       <Run>opqrst</Run>                   </TextBlock.Inlines>               </TextBlock>               <!--顯示 lblSource 中被使用者選中的文本(這裡的綁定不起作用,應該是bug,所以具體實現放到cs裡了)-->               <TextBlock FontSize="24" Name="lblCopy" Text="{Binding SelectedText, ElementName=lblSource}" />           </StackPanel>       </Grid>   </Page>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.