本文整理汇总了C#中System.Windows.Documents.TextRange.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.StartsWith方法的具体用法?C# TextRange.StartsWith怎么用?C# TextRange.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.StartsWith方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertSelectedEntry
private void InsertSelectedEntry(char characterInsertion)
{
if (this.intellisenseListBox.SelectedIndex <= -1 || !this.intellisensePopup.IsOpen)
return;
string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text;
int startIndex = text.LastIndexOf(' ');
string currentWord = startIndex != -1 ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]);
IntellisenseItem intellisenseItem = this.intellisenseListBox.SelectedItem as IntellisenseItem;
bool flag = text.StartsWith("d ", StringComparison.InvariantCultureIgnoreCase) && !IntellisenseAdorner.DM_EXPRESSION_WITH_END_SPACE.IsMatch(text);
string textData = this.IgnorePrefix || flag ? intellisenseItem.FilterValue : intellisenseItem.DisplayValue;
if (textData.StartsWith("@") || textData.StartsWith("#"))
{
int charactersToDelete = IntellisenseAdorner.GetNumberOfCharactersToDelete(currentWord, textData.StartsWith("@") ? "@" : "#");
if (currentWord.EndsWith(" "))
this.richTextBox.CaretPosition.DeleteTextInRun(-(charactersToDelete - 1));
else
this.richTextBox.CaretPosition.DeleteTextInRun(-charactersToDelete);
}
else if (currentWord.EndsWith(" "))
this.richTextBox.CaretPosition.DeleteTextInRun(-(currentWord.Length - 1));
else
this.richTextBox.CaretPosition.DeleteTextInRun(-currentWord.Length);
if ((int)characterInsertion != 0 && !this.IgnorePrefix)
textData = textData + (object)characterInsertion;
this.richTextBox.CaretPosition = this.richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) ?? this.richTextBox.CaretPosition;
if (!flag)
{
this.richTextBox.CaretPosition.InsertTextInRun(textData);
}
else
{
this.richTextBox.CaretPosition.InsertTextInRun(textData);
Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)intellisenseItem.FilterValue), (object)CommonCommands.MultiAccountifyToken((Enum)ViewModelMessages.DirectMessage, intellisenseItem.TwitterAccountID));
}
this.ignoreDisplay = true;
}
示例2: RichTextBox_TextChanged
private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_isLoading)
return;
_isLoading = true;
RichTextBox t = sender as RichTextBox;
if (t == null)
return;
BlockCollection bc = t.Document.Blocks;
foreach (Block b in bc)
{
if (b is Paragraph)
{
var para = b as Paragraph;
string text = new TextRange(para.ContentStart, para.ContentEnd).Text;
bool isProject = text.EndsWith(":");
bool isTask = text.StartsWith("-") || text.StartsWith("*");
bool isNote = !isProject && !isTask;
bool isDone = text.Contains("@done");
para.Foreground = isNote ? Brushes.DimGray : Brushes.Black;
para.FontSize = isProject ? 16 : 12;
para.TextDecorations = isDone ? TextDecorations.Strikethrough : null;
}
}
_isLoading = false;
}
示例3: FormatExisting
private void FormatExisting()
{
IEnumerator<Block> paras = MainTextArea.Document.Blocks.GetEnumerator();
string currentText;
Paragraph newPara;
List<Block> newBlocks = new List<Block>();
for (int i = 0; i < MainTextArea.Document.Blocks.Count; i++)
{
paras.MoveNext();
if (paras.Current.Tag == null)
{
currentText = new TextRange(paras.Current.ContentStart, paras.Current.ContentEnd).Text;
newPara = new Paragraph();
foreach (string symbol in StyleSymbol)
{
if (currentText.StartsWith(symbol))
{
currentText = currentText.Remove(0, symbol.Length);
newPara.Tag = StyleName[Array.IndexOf(StyleSymbol, symbol)];
break;
}
}
newPara.Inlines.Add(new Run(currentText));
ChangeParagraphStyle((Paragraph)newPara, newPara.Tag.ToString());
}
else
{
newPara = (Paragraph)paras.Current;
}
newBlocks.Add(newPara);
}
MainTextArea.Document.Blocks.Clear();
MainTextArea.Document.Blocks.AddRange(newBlocks);
}