本文整理汇总了C#中System.Windows.Documents.TextRange.Select方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.Select方法的具体用法?C# TextRange.Select怎么用?C# TextRange.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserControl_IsVisibleChanged
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (this.Visibility == Visibility.Visible)
{
// Show the story, hide the editor
StoryViewBorder.Visibility = Visibility.Visible;
StoryEditBorder.Visibility = Visibility.Hidden;
// Load the person story into the viewer
LoadStoryText(StoryViewer.Document);
// Display all text in constrast color to the StoryViewer background.
TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
// Hide the photo tags and photo edit buttons if there is no main photo.
if (DisplayPhoto.Source == null)
{
TagsStackPanel.Visibility = Visibility.Hidden;
PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
}
// Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
}
}
示例2: Paste_RequestNavigate
private void Paste_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
TextPointer start = this._rtb.Document.ContentStart,
end = this._rtb.Document.ContentEnd;
TextRange tr = new TextRange(start, end);
tr.Select(start, end);
MemoryStream ms;
StringBuilder sb = new StringBuilder();
foreach (String dataFormat in _listOfFormats)
{
if (tr.CanSave(dataFormat))
{
ms = new MemoryStream();
tr.Save(ms, dataFormat);
ms.Seek(0, SeekOrigin.Begin);
sb.AppendLine(dataFormat);
foreach (char c in ms.ToArray().Select<byte, char>((b) => (char)b))
{
sb.Append(c);
}
sb.AppendLine();
}
//_tb.Text = sb.ToString();
}
}
示例3: OnSkinChanged
/// <summary>
/// The details of a person changed.
/// </summary>
public void OnSkinChanged()
{
// Display all text in constrast color to the StoryViewer background.
TextRange textRange = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
}
示例4: Redo
public override void Redo(RichTextBox edit)
{
FlowDocument document = edit.Document;
__DataStream.Seek(0, SeekOrigin.Begin);
TextRange whole = new TextRange(document.ContentStart, document.ContentEnd);
TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
TextPointer end = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, __OffsetEnd);
whole.Select(start, end);
whole.Load(__DataStream, DataFormats.Xaml);
edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionAfter);
}
示例5: LoadPlainText
private void LoadPlainText(string text,ref FlowDocumentReader fdr)
{
fdr.Document.PageWidth=816;
TextRange tr=
new TextRange
(
fdr.Document.ContentStart,
fdr.Document.ContentEnd
)
{
Text=text
};
tr.Select
(
fdr.Document.ContentStart,
fdr.Document.ContentStart
);
}
示例6: UserControl_IsVisibleChanged
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (this.Visibility == Visibility.Visible)
{
// Load the person story into the viewer
LoadStoryText(StoryViewer.Document);
StoryViewBorder.Visibility = Visibility.Visible;
// Display all text in constrast color to the StoryViewer background.
TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
// Hide the Story Edit
StoryEditBorder.Visibility = Visibility.Hidden;
if (DisplayPhoto.Source == null)
{
TagsStackPanel.Visibility = Visibility.Hidden;
PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
}
}
}
示例7: Window_Closing
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
TextPointer start = this._rtb.Document.ContentStart,
end = this._rtb.Document.ContentEnd;
TextRange tr = new TextRange(start, end);
tr.Select(start, end);
if (tr.CanSave(DataFormats.Xaml))
{
FileInfo fi = new FileInfo("proba.xaml");
if (fi.Exists)
fi.Delete();
FileStream fs = fi.Create();
tr.Save(fs, DataFormats.Xaml);
fs.Flush();
fs.Close();
}
}
示例8: PasteMergeableTextFragment
// Helper for PasteTextFragment
private static void PasteMergeableTextFragment(TextElement fragment, TextRange range, TextPointer insertionPosition)
{
TextPointer fragmentStart;
TextPointer fragmentEnd;
if (fragment is Span)
{
// Split structure at insertion point in target
insertionPosition = TextRangeEdit.SplitFormattingElements(insertionPosition, /*keepEmptyFormatting:*/false);
Invariant.Assert(insertionPosition.Parent is Paragraph, "insertionPosition must be in a scope of a Paragraph after splitting formatting elements");
// Move the whole Span into the insertion point
fragment.RepositionWithContent(insertionPosition);
// Store edge positions of inserted content
fragmentStart = fragment.ElementStart;
fragmentEnd = fragment.ElementEnd;
// Remove wrapper from a tree
fragment.Reposition(null, null);
ValidateMergingPositions(typeof(Inline), fragmentStart, fragmentEnd);
// Transfer inheritable contextual properties
ApplyContextualProperties(fragmentStart, fragmentEnd, fragment);
}
else
{
// Correct leading nested List elements in the fragment
CorrectLeadingNestedLists((Section)fragment);
// Split a paragraph at insertion position
bool needFirstParagraphMerging = SplitParagraphForPasting(ref insertionPosition);
// Move the whole Section into the insertion point
fragment.RepositionWithContent(insertionPosition);
// Store edge positions of inserted content
fragmentStart = fragment.ElementStart;
fragmentEnd = fragment.ElementEnd.GetPositionAtOffset(0, LogicalDirection.Forward); // need forward orientation to stick with the following content during merge at fragmentStart position
// And unwrap the root Section
fragment.Reposition(null, null);
ValidateMergingPositions(typeof(Block), fragmentStart, fragmentEnd);
// Transfer inheritable contextual properties
ApplyContextualProperties(fragmentStart, fragmentEnd, fragment);
// Merge paragraphs on fragment boundaries
if (needFirstParagraphMerging)
{
MergeParagraphsAtPosition(fragmentStart, /*mergingOnFragmentStart:*/true);
}
// Get an indication that we need to merge last paragraph
if (!((Section)fragment).HasTrailingParagraphBreakOnPaste)
{
MergeParagraphsAtPosition(fragmentEnd, /*mergingOnFragmentStart:*/false);
}
}
//
// For paragraph pasting move range end to the following paragraph, because
// it must include an ending paragraph break (in case of no-merging)
if (fragment is Section && ((Section)fragment).HasTrailingParagraphBreakOnPaste)
{
fragmentEnd = fragmentEnd.GetInsertionPosition(LogicalDirection.Forward);
}
// Select pasted content
range.Select(fragmentStart, fragmentEnd);
}
示例9: PasteNonMergeableTextFragment
// Helper for PasteTextFragment
private static void PasteNonMergeableTextFragment(TextElement fragment, TextRange range)
{
// We cannot split Hyperlink or other non-splittable inline ancestor.
// Paste text content of fragment in such case.
// Get text content to be pasted.
string fragmentText = TextRangeBase.GetTextInternal(fragment.ElementStart, fragment.ElementEnd);
// Paste text into our empty target range.
//
range.Text = fragmentText;
// Select pasted content
range.Select(range.Start, range.End);
}
示例10: ResetTextColor
/// <summary>
/// resets the colors for all of the text in the given text box
/// </summary>
/// <param name="box"></param>
private static void ResetTextColor(RichTextBox box)
{
var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
var startPos = GetPoint(box.Document.ContentStart, 0);
textRange.Select(box.Document.ContentStart, box.Document.ContentEnd);
textRange.ApplyPropertyValue(TextElement.ForegroundProperty,
new SolidColorBrush(Colors.Black));
textRange.ApplyPropertyValue(TextElement.BackgroundProperty,
new SolidColorBrush(Colors.White));
}
示例11: ColorizeText
private static void ColorizeText(RichTextBox box, int offset, int length)
{
var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
var startPos = GetPoint(box.Document.ContentStart, offset);
var endPos = GetPoint(box.Document.ContentStart, offset + length);
Console.WriteLine("{0},offset from start:{1}, end: {2}", box.Name, box.Document.ContentStart.GetOffsetToPosition(startPos), endPos);
textRange.Select(startPos, endPos);
textRange.ApplyPropertyValue(TextElement.ForegroundProperty,
new SolidColorBrush(_ltForeground[_indexColorLookup % _ltForeground.Length]));
textRange.ApplyPropertyValue(TextElement.BackgroundProperty,
new SolidColorBrush(_ltBackground[_indexColorLookup % _ltForeground.Length]));
}
示例12: SaveText
private void SaveText(ref FlowDocumentReader fdr)
{
string mask="Rich Text Format (*.rtf)|*.rtf|"+app.Language.TextDocument+" (*.txt)|*.txt|"+app.Language.AllFiles+" (*.*)|*.*";
SaveFileDialog Save=CreateSaveDialog(mask,app.Language.Save);
if(Save.ShowDialog(this).GetValueOrDefault())
{
FileStream file=SafeFileMethods.CreateFile(Save.FileName);
if(file==null)
{
ShowNotification(app.Language.SaveTextError,Title,System.Windows.Forms.ToolTipIcon.Error);
return;
}
TextRange tr=new TextRange(fdr.Document.ContentStart,fdr.Document.ContentEnd);
tr.Select(fdr.Document.ContentStart,fdr.Document.ContentEnd);
if(Save.FilterIndex>1)
tr.Save(file,DataFormats.Text);
else tr.Save(file,DataFormats.Rtf);
tr.Select(fdr.Document.ContentStart,fdr.Document.ContentStart);
file.Close();
}
}
示例13: SaveStoryButton_Click
private void SaveStoryButton_Click(object sender, RoutedEventArgs e)
{
Person person = (Person)this.DataContext;
if (person != null)
{
// Pass in a TextRange object to save the story
TextRange textRange = new TextRange(StoryRichTextBox.Document.ContentStart, StoryRichTextBox.Document.ContentEnd);
person.Story = new Story();
string storyFileName = new StringBuilder(person.Name).Append(" {").Append(person.Id).Append("}").Append(".rtf").ToString();
person.Story.Save(textRange, storyFileName);
// Display the rich text in the viewer
LoadStoryText(StoryViewer.Document);
// Display all text in constrast color to the StoryViewer background.
TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
}
StoryEditBorder.Visibility = Visibility.Hidden;
StoryViewBorder.Visibility = Visibility.Visible;
}
示例14: SaveStoryButton_Click
private void SaveStoryButton_Click(object sender, RoutedEventArgs e)
{
Person person = (Person)this.DataContext;
if (person != null)
{
// Pass in a TextRange object to save the story
TextRange textRange = new TextRange(StoryRichTextBox.Document.ContentStart, StoryRichTextBox.Document.ContentEnd);
person.Story = new Story();
string storyFileName = new StringBuilder(person.Name).Append(" {").Append(person.Id).Append("}").Append(".rtf").ToString();
person.Story.Save(textRange, storyFileName);
// Display the rich text in the viewer
LoadStoryText(StoryViewer.Document);
// Display all text in constrast color to the StoryViewer background.
TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
}
// Switch to view mode
StoryEditBorder.Visibility = Visibility.Hidden;
StoryViewBorder.Visibility = Visibility.Visible;
// Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
}
示例15: MergeCells
// ....................................................................
//
// Cell editing
//
// ....................................................................
/// <summary>
/// Merges several cells horizontally.
/// </summary>
/// <param name="textRange">
/// TextRange contining cells to be merged.
/// </param>
/// <returns>
/// TextRange containing resulted merged cell.
/// Null in case if textRange cannot be merged.
/// </returns>
internal static TextRange MergeCells(TextRange textRange)
{
Invariant.Assert(textRange != null, "null check: textRange");
TableCell startCell;
TableCell endCell;
TableRow startRow;
TableRow endRow;
TableRowGroup startRowGroup;
TableRowGroup endRowGroup;
Table startTable;
Table endTable;
if (!IdentifyTableElements(textRange.Start, textRange.End, /*includeCellAtMovingPosition:*/false, out startCell, out endCell, out startRow, out endRow, out startRowGroup, out endRowGroup, out startTable, out endTable))
{
return null;
}
if (startCell == null || endCell == null)
{
return null;
}
Invariant.Assert(startCell.Row.RowGroup == endCell.Row.RowGroup, "startCell and endCell must belong to the same RowGroup");
Invariant.Assert(startCell.Row.Index <= endCell.Row.Index, "startCell.Row.Index must be <= endCell.Row.Index");
Invariant.Assert(startCell.ColumnIndex <= endCell.ColumnIndex + endCell.ColumnSpan - 1, "startCell.ColumnIndex must be <= an index+span of an endCell");
// Perform a merge
TextRange result = MergeCellRange(startCell.Row.RowGroup, //
startCell.Row.Index, // topRow
endCell.Row.Index + endCell.RowSpan - 1, // bottomRow
startCell.ColumnIndex, // leftColumn
endCell.ColumnIndex + endCell.ColumnSpan - 1); // rightColumn
if (result != null)
{
textRange.Select(textRange.Start, textRange.End);
}
return result;
}