1
我的RichTextBlock中包含超链接。我在超链接的点击事件中添加了一些代码块。问题是,无论何时单击超链接,我的应用程序都会因“访问冲突”异常而崩溃。只有当键盘可见时才会发生这种情况。如果键盘被辞退,那么我不会得到例外。此外,这只发生在WP8.1设备而不是W10设备上。以下是我的代码。RichTextBlock中的超链接导致应用程序崩溃,在我的Windows Phone 8.1应用程序中单击
XAML
<StackPanel>
<RichTextBlock FontSize="40" x:Name="rtb"/>
<TextBox x:Name="tb"/>
</StackPanel>
代码背后
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
rtb.Blocks.Add(ContentForRichTextBox("9910918444"));
}
这是我要建在RichTextBox
public Paragraph ContentForRichTextBox(string plainString)
{
Paragraph richContent = new Paragraph();
try
{
string[] plainStringSplit = plainString.Split(' ');
foreach (var word in plainStringSplit)
{
var number = new Hyperlink();
number.Foreground = new SolidColorBrush(Colors.DarkBlue);
number.Inlines.Add(new Run { Text = word });
number.Click += (s, e) =>
{
try
{
Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(word, "Some dude");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception HelperMethod number.Click : " + ex.ToString());
}
};
richContent.Inlines.Add(number);
//add a space
if (plainStringSplit.Last() != word)
{
richContent.Inlines.Add(new Run { Text = " " });
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception HelperMethod ContentForRichTextBox : " + ex.ToString());
}
return richContent;
}
每当我点击超链接的内容和我的文本框是在焦点上,应用程序崩溃,例外
The program '[2992] App5.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
任何帮助将不胜感激。
工程就像一个魅力。谢谢! – thatrohit