MainPage.xaml中
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <TextBlock Height="200" TextWrapping="Wrap" Loaded="TextBlock_Loaded" Tapped="TextBlock_Tapped"> dsdsdsdsadsadddsdsdsdhttp://www.baidu.com dsadsadsadsahttps://www.baidu.com1 daewqewqeqwewqdaewq dsdsdsdsadsadddsdsdsdhttp://www.baidu.com6 dsadsadsadsahttps://www.baidu.com2 daewqewqeqwewqdaewq dsdsdsdsadsadddsdsdsdhttp://www.baidu.com7 dsadsadsadsahttps://www.baidu.com3 daewqewqeqwewqdaewq dsdsdsdsadsadddsdsdsdhttp://www.baidu.com8 dsadsadsadsahttps://www.baidu.com4 daewqewqeqwewqdaewq dsdsdsdsadsadddsdsdsdhttp://www.baidu.com9 dsadsadsadsahttps://www.baidu.com5 daewqewqeqwewqdaewq <FlyoutBase.AttachedFlyout> <Flyout x:Name="HyperText" Placement="Full"> <StackPanel> <ListView Name="ttt" SelectionChanged="ttt_SelectionChanged"/> </StackPanel> </Flyout> </FlyoutBase.AttachedFlyout> </TextBlock> <StackPanel Orientation="Horizontal"> <Button Content="粘贴超链接" Click="Button_Click" /> <TextBox Name="hhh"/> </StackPanel> </StackPanel>
MainPage.cs中
using System.Text.RegularExpressions; using Windows.ApplicationModel.DataTransfer; private void TextBlock_Loaded(object sender,RoutedEventArgs e) { string str = ((TextBlock)sender).Text.ToString().ToLower(); string pattern = @"https?://[^\s]+\s"; MatchCollection mc = Regex.Matches(str,pattern); if(mc.Count > 0) { ttt.Items.Clear(); foreach (Match t in mc) { ttt.Items.Add(t.Value.ToString().Trim()); } } } private void ttt_SelectionChanged(object sender,SelectionChangedEventArgs e) { var ddd = (ListView)sender; DataPackage dp = new DataPackage(); dp.SetText(ddd.SelectedItem.ToString()); Clipboard.SetContent(dp); HyperText.Hide(); } private void TextBlock_Tapped(object sender,TappedRoutedEventArgs e) { var fff = (TextBlock)sender; FlyoutBase.ShowAttachedFlyout(fff); } private async void Button_Click(object sender,RoutedEventArgs e) { DataPackageView con = Clipboard.GetContent(); if (con.Contains(StandardDataFormats.Text)) { hhh.Text = await con.GetTextAsync(); } }