本文整理汇总了C#中System.Windows.Documents.TextRange.DeleteTextInRun方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.DeleteTextInRun方法的具体用法?C# TextRange.DeleteTextInRun怎么用?C# TextRange.DeleteTextInRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.DeleteTextInRun方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: adornedElement_PreviewKeyUp
private void adornedElement_PreviewKeyUp(object sender, KeyEventArgs e)
{
if ((this.richTextBox != null) && (((e != null) && (e.Key == Key.Space)) || ((e == null) && this.performURLParsing)))
{
bool isWWWPrefixed;
this.performURLParsing = false;
string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.Document.ContentEnd).Text;
string str2 = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text;
int length = str2.Length;
if (((length - 1) <= text.Length) && (length != 0))
{
int startIndex = -1;
if ((length - 2) >= 0)
{
startIndex = text.LastIndexOf("http://", (int)(length - 2));
startIndex = (startIndex == -1) ? text.LastIndexOf("https://", (int)(length - 2)) : startIndex;
startIndex = (startIndex == -1) ? (startIndex = text.LastIndexOf("www.", (int)(length - 2))) : startIndex;
}
if (startIndex == -1)
{
startIndex = 0;
}
if (str2.Substring(0, str2.Length - 1).EndsWith("\r\n"))
{
startIndex = length - 1;
}
this.lastWord = text.Substring(startIndex, length - startIndex);
isWWWPrefixed = false;
int num3 = this.lastWord.LastIndexOf("http://");
num3 = (num3 == -1) ? this.lastWord.LastIndexOf("https://") : num3;
if (num3 == -1)
{
num3 = this.lastWord.LastIndexOf("www.");
isWWWPrefixed = true;
}
if (num3 != -1)
{
string url;
ContextMenu buttonContextMenu;
Button button;
MenuItem expandContractMenuItem;
MenuItem gotoLinkMenuitem;
Func<string> shortenURLDelegate;
int index = this.lastWord.IndexOf(' ', num3);
if (index != -1)
{
url = this.lastWord.Substring(num3, index - num3);
int num5 = url.Length;
if (isWWWPrefixed)
{
num5 += "http://".Length;
}
if ((num5 >= this.URL_LENGTH_THRESHOLD) && !this.IsAlreadyShortened(url))
{
int x = text.IndexOf(url) - GetInlineUIContainerCountUpToPointer(this.richTextBox, this.richTextBox.CaretPosition);
TextPointer start = new TextRange(GetPoint(this.richTextBox.Document.ContentStart, x), this.richTextBox.Document.ContentEnd).Start;
start.DeleteTextInRun(url.Length);
buttonContextMenu = new ContextMenu();
button = new Button();
button.SetResourceReference(FrameworkElement.StyleProperty, "URLButton");
button.Content = "shortening...";
button.Click += delegate(object s, RoutedEventArgs e2)
{
buttonContextMenu.PlacementTarget = button;
buttonContextMenu.Placement = PlacementMode.Bottom;
buttonContextMenu.IsOpen = true;
};
expandContractMenuItem = new MenuItem
{
Header = "Expand link",
IsEnabled = false
};
gotoLinkMenuitem = new MenuItem
{
Header = "Open link in browser",
IsEnabled = false
};
buttonContextMenu.Items.Add(gotoLinkMenuitem);
buttonContextMenu.Items.Add(expandContractMenuItem);
InlineUIContainer container = new InlineUIContainer(button, start);
shortenURLDelegate = delegate
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
if (CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID) != null)
{
string key = CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID).Name;
if (!App.ShortenedURLCache.ContainsKey(key))
{
Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
App.ShortenedURLCache.Add(key, dictionary2);
dictionary = dictionary2;
}
else
{
dictionary = App.ShortenedURLCache[key];
}
}
string text1 = url;
if (isWWWPrefixed)
{
//.........这里部分代码省略.........