2016-04-15 63 views
0

我正在開發UWP(Win10 - VS2015)應用程序。我需要Windows平臺中的令牌文本框。任何想法請,如何開始和創建此控件,然後在文本框內寫入文本並放置空間或只需點擊該文本,它應該轉換爲選定的令牌。看照片(它只是想法)。我需要這種類型的控制。UWP - 如何創建TokenAutoComplete控件

您也可以從這個帖子TokenAutoComplete

enter image description here

+0

有你提到這個鏈接http://stackoverflow.com/questions/36237644 /如何對創建-A-標記化控制換UWP-如已知的從 - 前景-時-使用到? – Archana

+0

你好@Archana,再次感謝你的關注。我會查看你的推薦鏈接和博客裏面,然後很快就會回到你InshaAllah。 :) –

+0

@LovetoCode(Archana),我讀過你介紹的鏈接裏面的文章。這實際上是一個偉大的文章,尤其是WPF用戶。我正在嘗試在UWP應用程序中實現它,但在UWP中獲取很多錯誤bcoz RichEditBox沒有像在WPF RichTextBox中那樣的選項。因此,要求您在UWP中解決這個控制問題並分享它。這將非常感激。再次感謝。 –

回答

1

得到的想法,我很張貼是初始代碼的代碼,你可以開始..

我用RichTextBlock和文本框builting控制。如果你把這兩個控件放在Gridview中的WrapPanel中。你可能會得到你想要的類似控制,但我沒有嘗試過。

<RichTextBlock x:Name="tokenblock"> 
       <Paragraph> 

       </Paragraph> 

      </RichTextBlock> 
      <TextBox TextChanged="TextBox_TextChanged"/> 

後面的代碼是這樣的

private void TextBox_TextChanged(object sender, TextChangedEventArgs e) 
     { 
      string text = (sender as TextBox).Text; 
      if (text.Contains(';')) 
      { 
       Paragraph para; 
       text = text.Substring(0, text.LastIndexOf(';')); 
       if (tokenblock.Blocks.Count > 0) 
        para = tokenblock.Blocks[0] as Paragraph; 
       else 
       para = new Paragraph(); 
       InlineUIContainer inline = new InlineUIContainer(); 
       Border br = new Border(); 
       br.Background = new SolidColorBrush(Colors.Gray); 
       br.CornerRadius = new CornerRadius(10); 
       TextBlock tb = new TextBlock(); 
       br.MinWidth = 70; 
       br.MaxWidth = 150; 
       tb.Text = text; 
       tb.TextWrapping = TextWrapping.Wrap; 
       tb.Margin =new Thickness(10, 10, 10, 10); 
       br.Child = tb; 
       inline.Child = br; 
       para.Inlines.Add(inline); 
       (sender as TextBox).Text = ""; 
      } 

//下面的代碼我沒試過

<GridView x:Name="myGridView" IsItemClickEnabled="True"> 
     <GridView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="5"/> 
      </ItemsPanelTemplate> 
     </GridView.ItemsPanel> 
//here you have to put RichTextBlock and textbox as two gridview items 
+0

好,我會嘗試這個,並讓你知道InshaAllah。謝謝。 –

+1

非常感謝,它工作完美。並抱歉回覆遲到,就在今天我使用了這個代碼,並根據我的需要做了一些微小的更改,它的工作非常完美......在對齊和包裝方面仍然有點問題,但是完成了95%的工作。謝謝。完成後我會修改和分享代碼。 回到你很快InshaAllah。 –