<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      開發WinRT自定義組件之富文本框

      富文本框是常用的組件之一,多用于文章排版、用戶評論等。

      WinRT組件中內置了兩個:RichEditBox、RichTextBlock。RichEditBox可以編輯,RichTextBlock只用來顯示。

      由于內置的組件缺少工具欄,故我準備擴展一下,添加一些常用的功能。

      測試代碼下載

       

      1、首先創建一個 WinRT 類庫項目:

       

      2、添加Templated Control:

      會自動創建Themes文件夾與Generic.xaml文件:

      其中自定義組件的類中會缺少前綴,手動添加即可:

       

      3、設計RichEditBoxX的樣式:

       

       1     <Style TargetType="winrt:RichEditBoxX">
       2         <Setter Property="Template">
       3             <Setter.Value>
       4                 <ControlTemplate TargetType="winrt:RichEditBoxX">
       5                     <StackPanel>
       6                         <StackPanel Orientation="Horizontal">
       7                             <ComboBox Name="txtFontFamily" Width="80"></ComboBox>
       8                             <ComboBox Name="txtFontSize" Width="80"></ComboBox>
       9                             <Button Name="btnWeight" Width="50" Content="B"></Button>
      10                             <Button Name="btnStyle" Width="50" Content="I" FontStyle="Italic"></Button>
      11                             <Button Name="btnUnderline" Width="50" Content="U"></Button>
      12                             <ComboBox Name="txtAlign" Width="50">
      13                                 <ComboBox.Items>
      14                                     <ContentControl Name="labLeft" Content="Left" Width="50"></ContentControl>
      15                                     <ContentControl Name="labCenter" Content="Center" Width="50"></ContentControl>
      16                                     <ContentControl Name="labRight" Content="Right" Width="50"></ContentControl>
      17                                     <ContentControl Name="labJustify" Content="Justify" Width="50"></ContentControl>
      18                                 </ComboBox.Items>
      19                             </ComboBox>
      20                             <Button Name="btnForeground" Content="Foreground" Width="120"></Button>
      21                             <Button Name="btnBackground" Content="Background" Width="120"></Button>
      22                             <Button Name="btnImage" Content="Image" Width="80"></Button>
      23                             <Button Name="btnVideo" Content="Video" Width="80"></Button>
      24                         </StackPanel>
      25                         <RichEditBox Name="txtRichEdit" AcceptsReturn="True" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
      26                             
      27                         </RichEditBox>
      28                     </StackPanel>
      29                 </ControlTemplate>
      30             </Setter.Value>
      31         </Setter>
      32     </Style>

       

      語法與WPF、Silverlight基本一致,注意添加命令空間的語法有所改變:

      xmlns:winrt="using:BrooksCom.WinRT.Control"

      目前無法將自定義組件的XAML單獨拆分成多個文件,要被迫寫在Generic.xaml中,這應該是一個疏忽,希望正式版能改正這個問題。

      目前Generic.xaml依然不能可視化設計,對于美工水平相當湊合的我來說,想好看點是種奢望 J

      順便期待下Blend 5正式版,什么時候能發布,好歹把WPF、Silverlight、WinRT、Windows Phone 四種平臺集成到一起,不要分為多個了。

      比較奇怪的是WinRT中居然沒有Label控件,我暫且使用ContentControl代替。

       

      4、設置字體功能使用了WCF服務:

       1     public class SrvFont : ISrvFont
       2     {
       3         public List<string> DoWork()
       4         {
       5             List<string> __list = new List<string>();
       6             InstalledFontCollection fonts = new InstalledFontCollection();
       7             foreach (FontFamily font in fonts.Families)
       8             {
       9                 __list.Add(font.Name);
      10             }
      11 
      12             return __list;
      13         }
      14     }

      使用了C# 5.0的異步方法,WinRT中幾乎都是異步方法,以后要適應這種風格了:

       1         protected async override void OnApplyTemplate()
       2         {
       3             base.OnApplyTemplate();
       4 
       5             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
       6 
       7             ComboBox __txtFontFamily = this.GetTemplateChild("txtFontFamily"as ComboBox;
       8             SrvFont.SrvFontClient __proxy = new SrvFont.SrvFontClient();
       9             System.Collections.ObjectModel.ObservableCollection<string> __list = await __proxy.DoWorkAsync();
      10             foreach (string s in __list)
      11             {
      12                 __txtFontFamily.Items.Add(s);
      13             }
      14 
      15             __txtFontFamily.SelectionChanged += __txtFontFamily_SelectionChanged;

       

      5、設置字體、字號等格式:

      使用 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat 來設置樣式。

       1         void __txtFontFamily_SelectionChanged(object sender, SelectionChangedEventArgs e)
       2         {
       3             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
       4             ComboBox __txtFontFamily = this.GetTemplateChild("txtFontFamily"as ComboBox;
       5             __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Name = __txtFontFamily.SelectedItem.ToString();
       6         }
       7 
       8         void __txtFontSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
       9         {
      10             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
      11             ComboBox __txtFontSize = this.GetTemplateChild("txtFontSize"as ComboBox;
      12             __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Size = float.Parse(__txtFontSize.SelectedItem.ToString());
      13         }

       

      字體加粗的枚舉比較特殊,類似一個開關:

       1         void __btnWeight_Click(object sender, RoutedEventArgs e)
       2         {
       3             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
       4             Button __btnWeight = this.GetTemplateChild("btnWeight"as Button;
       5 
       6             if (__txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Bold == Windows.UI.Text.FormatEffect.On)
       7             {
       8                 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Bold = Windows.UI.Text.FormatEffect.Off;
       9             }
      10             else
      11             {
      12                 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Bold = Windows.UI.Text.FormatEffect.On;
      13             }
      14         }
      15 
      16         void __btnStyle_Click(object sender, RoutedEventArgs e)
      17         {
      18             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
      19             Button __btnStyle = this.GetTemplateChild("btnStyle"as Button;
      20             if (__txtRichEdit.Document.Selection.FormattedText.CharacterFormat.FontStyle == Windows.UI.Text.FontStyle.Italic)
      21             {
      22                 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.FontStyle = Windows.UI.Text.FontStyle.Normal;
      23             }
      24             else
      25             {
      26                 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.FontStyle = Windows.UI.Text.FontStyle.Italic;
      27             }
      28         }
      29 
      30         void __btnUnderline_Click(object sender, RoutedEventArgs e)
      31         {
      32             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
      33             Button __btnUnderline = this.GetTemplateChild("btnUnderline"as Button;
      34             if (__txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Underline == Windows.UI.Text.UnderlineType.None)
      35             {
      36                 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Underline = Windows.UI.Text.UnderlineType.Single;
      37             }
      38             else
      39             {
      40                 __txtRichEdit.Document.Selection.FormattedText.CharacterFormat.Underline = Windows.UI.Text.UnderlineType.None;
      41             }
      42         }

       

      使用ParagraphFormat.Alignment設置對齊方式:

       1         void __txtAlign_SelectionChanged(object sender, SelectionChangedEventArgs e)
       2         {
       3             RichEditBox __txtRichEdit = this.GetTemplateChild("txtRichEdit"as RichEditBox;
       4             ComboBox __txtAlign = this.GetTemplateChild("txtAlign"as ComboBox;
       5             switch (((sender as ComboBox).SelectedItem as ContentControl).Name)
       6             {
       7                 case "labLeft":
       8                     __txtRichEdit.Document.Selection.FormattedText.FormattedText.ParagraphFormat.Alignment = Windows.UI.Text.ParagraphAlignment.Left;
       9                     break;
      10                 case "labCenter":
      11                     __txtRichEdit.Document.Selection.FormattedText.FormattedText.ParagraphFormat.Alignment = Windows.UI.Text.ParagraphAlignment.Center;
      12                     break;
      13                 case "labRight":
      14                     __txtRichEdit.Document.Selection.FormattedText.FormattedText.ParagraphFormat.Alignment = Windows.UI.Text.ParagraphAlignment.Right;
      15                     break;
      16                 case "labJustify":
      17                     __txtRichEdit.Document.Selection.FormattedText.FormattedText.ParagraphFormat.Alignment = Windows.UI.Text.ParagraphAlignment.Justify;
      18                     break;
      19                 default:
      20                     break;
      21             }
      22         }

       

      設置顏色、插入圖片、視頻等還沒有做好,有些問題,以后慢慢完善。

       

      最終效果:

      posted @ 2012-04-10 21:32  江蘇瑞步科技  閱讀(1638)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲午夜无码久久久久小说| 一本一本久久a久久综合精品| 精品久久人人做爽综合| 亚洲sm另类一区二区三区| 91无码人妻精品一区| 欧美激情内射喷水高潮| 国产偷国产偷亚洲高清午夜| av新版天堂在线观看| 天堂资源在线| 欧美性猛交xxxx乱大交丰满| 精品国产粉嫩内射白浆内射双马尾| 中文无码精品a∨在线| 少妇高潮喷水正在播放| 亚洲欭美日韩颜射在线二| 福利网午夜视频一区二区| 肥臀浪妇太爽了快点再快点| 温宿县| 国产日韩入口一区二区| 三上悠亚久久精品| 四虎永久精品在线视频| 亚洲精品无码av人在线观看| 丁香五月婷激情综合第九色| 亚洲男人第一无码av网站| 成人国产精品日本在线观看| 自拍视频在线观看三级| 亚洲精品日韩在线观看| 884aa四虎影成人精品| 亚洲男女羞羞无遮挡久久丫 | 亚洲精品理论电影在线观看| 精品久久综合日本久久网| 一卡2卡三卡4卡免费网站| 国产99青青成人A在线| 国产一区二区精品久久凹凸| 无码国产成人午夜电影在线观看| 国产成人a在线观看视频| 国产精品午夜福利精品| 宁安市| 国产日韩AV免费无码一区二区三区| 成人免费看片又大又黄| 久9re热视频这里只有精品免费| 日韩高清福利视频在线观看|