本文整理汇总了C#中System.Windows.Documents.Block类的典型用法代码示例。如果您正苦于以下问题:C# Block类的具体用法?C# Block怎么用?C# Block使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Block类属于System.Windows.Documents命名空间,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBlock
public static void AddBlock(Block from, FlowDocument to)
{
if (from != null)
{
//if (from is ItemsContent)
//{
// ((ItemsContent)from).RunBeforeCopy();
//}
//else
{
TextRange range = new TextRange(from.ContentStart, from.ContentEnd);
MemoryStream stream = new MemoryStream();
System.Windows.Markup.XamlWriter.Save(range, stream);
range.Save(stream, DataFormats.XamlPackage);
TextRange textRange2 = new TextRange(to.ContentEnd, to.ContentEnd);
textRange2.Load(stream, DataFormats.XamlPackage);
}
}
}
示例2: ReportPaginator
/// <summary>
/// Constructor
/// </summary>
/// <param name="report">report document</param>
/// <param name="data">report data</param>
/// <exception cref="ArgumentException">Flow document must have a specified page height</exception>
/// <exception cref="ArgumentException">Flow document must have a specified page width</exception>
/// <exception cref="ArgumentException">Flow document can have only one report header section</exception>
/// <exception cref="ArgumentException">Flow document can have only one report footer section</exception>
public ReportPaginator(ReportDocument report, ReportData data)
{
_report = report;
_data = data;
_flowDocument = report.CreateFlowDocument();
_pageSize = new Size(_flowDocument.PageWidth, _flowDocument.PageHeight);
if (_flowDocument.PageHeight == double.NaN) throw new ArgumentException("Flow document must have a specified page height");
if (_flowDocument.PageWidth == double.NaN) throw new ArgumentException("Flow document must have a specified page width");
_dynamicCache = new ReportPaginatorDynamicCache(_flowDocument);
ArrayList listPageHeaders = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportHeader));
if (listPageHeaders.Count > 1) throw new ArgumentException("Flow document can have only one report header section");
if (listPageHeaders.Count == 1) _blockPageHeader = (SectionReportHeader)listPageHeaders[0];
ArrayList listPageFooters = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportFooter));
if (listPageFooters.Count > 1) throw new ArgumentException("Flow document can have only one report footer section");
if (listPageFooters.Count == 1) _blockPageFooter = (SectionReportFooter)listPageFooters[0];
_paginator = ((IDocumentPaginatorSource)_flowDocument).DocumentPaginator;
// remove header and footer in our working copy
Block block = _flowDocument.Blocks.FirstBlock;
while (block != null)
{
Block thisBlock = block;
block = block.NextBlock;
if ((thisBlock == _blockPageHeader) || (thisBlock == _blockPageFooter)) _flowDocument.Blocks.Remove(thisBlock);
}
// get report context values
_reportContextValues = _dynamicCache.GetFlowDocumentVisualListByInterface(typeof(IInlineContextValue));
FillData();
}
示例3: AnchoredBlock
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
/// <summary>
/// Creates a new AnchoredBlock instance.
/// </summary>
/// <param name="block">
/// Optional child of the new AnchoredBlock, may be null.
/// </param>
/// <param name="insertionPosition">
/// Optional position at which to insert the new AnchoredBlock. May
/// be null.
/// </param>
protected AnchoredBlock(Block block, TextPointer insertionPosition)
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.BeginChange();
}
try
{
if (insertionPosition != null)
{
// This will throw InvalidOperationException if schema validity is violated.
insertionPosition.InsertInline(this);
}
if (block != null)
{
this.Blocks.Add(block);
}
}
finally
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.EndChange();
}
}
}
示例4: AddBlock
private void AddBlock(Block block, TextSelection selection)
{
if (selection == null || selection.End == null)
AddBlockToEnd(block);
else
_flowDocument.Blocks.InsertAfter(selection.End.GetInsertionPosition(LogicalDirection.Forward).Paragraph, block);
}
示例5: BlockComponent
public BlockComponent(Block block)
{
if (block == null) throw new ArgumentNullException(nameof(block));
Block = block;
SubscribeForEvents();
}
示例6: Serialize
public XmlElement Serialize(Block block, XmlDocument xmlDocument)
{
var image = (ImageBlock)block;
var imageElement = xmlDocument.CreateElement("Image");
var srcAttribute = xmlDocument.CreateAttribute("Src");
srcAttribute.InnerText = Path.GetFileName(image.Source.ToString());
imageElement.Attributes.Append(srcAttribute);
return imageElement;
}
示例7: readSocket
public Block readSocket(Block source, Block destination)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(0);
List<System.Windows.UIElement> components = innards.Children.ToList();
Debug.WriteLine("+" + components.ElementAt(0));
destination.innerPane.Children.Clear();
destination.innerPane.Children.Insert(0, source.innerPane.Children.ElementAt(0));
return destination;
}
示例8: ReadRuns
private static IEnumerable<string> ReadRuns(Block block)
{
var result = new List<string>();
if (block is Paragraph)
{
result.AddRange((block as Paragraph).Inlines.OfType<Run>().Select(inline => inline.Text.Trim()));
}
return result;
}
示例9: Section
/// <summary>
/// Initializes a new instance of a Section class specifying a first Block child for it.
/// </summary>
/// <param name="block">
/// Block element added to a Section as its first child.
/// </param>
public Section(Block block)
: base()
{
if (block == null)
{
throw new ArgumentNullException("block");
}
this.Blocks.Add(block);
}
示例10: AddBlock
private void AddBlock(Block block)
{
if (scroll == null)
scroll = reportViewer.Template.FindName("PART_ContentHost", reportViewer) as ScrollViewer;
if (scroll.ScrollableHeight - scroll.ExtentHeight < 5)
{
report.Blocks.Add(block);
scroll.ScrollToEnd();
}
else
report.Blocks.Add(block);
}
示例11: AddXaml
/// <summary>Adds XAML content to a RichTextBox.</summary>
/// <param name="richTextBox">The textbox to add to.</param>
/// <param name="xaml">The block to add.</param>
/// <remarks>This method effectively handles a Section block element if specified (adding all child Blocks to the textbox).</remarks>
public static void AddXaml(this RichTextBox richTextBox, Block xaml)
{
if (richTextBox == null) throw new ArgumentNullException("richTextBox");
if (xaml == null) throw new ArgumentNullException("xaml");
if (xaml is Section)
{
AddBlocks(richTextBox, ((Section)xaml).Blocks);
}
else
{
richTextBox.Blocks.Add(xaml);
}
}
示例12: ReportPaginator
// ReSharper restore InconsistentNaming
/// <summary>
/// Constructor
/// </summary>
/// <param name="report">report document</param>
/// <param name="data">report data</param>
/// <exception cref="ArgumentException">Flow document must have a specified page height</exception>
/// <exception cref="ArgumentException">Flow document must have a specified page width</exception>
/// <exception cref="ArgumentException">Flow document can have only one report header section</exception>
/// <exception cref="ArgumentException">Flow document can have only one report footer section</exception>
public ReportPaginator(ReportDocument report, ReportData data, Action<int, int> PageGeneratedCallBack = null, FlowDocument flowDocument = null)
{
_report = report;
_data = data;
_pageGeneratedCallBack = PageGeneratedCallBack;
_flowDocument = flowDocument;
if (_flowDocument == null)
_flowDocument = report.CreateFlowDocument();
_pageSize = new Size(_flowDocument.PageWidth, _flowDocument.PageHeight);
if (_flowDocument.PageHeight == double.NaN) throw new ArgumentException("Flow document must have a specified page height");
if (_flowDocument.PageWidth == double.NaN) throw new ArgumentException("Flow document must have a specified page width");
_dynamicCache = new ReportPaginatorDynamicCache(_flowDocument);
ArrayList listPageHeaders = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportHeader));
if (listPageHeaders.Count > 1) throw new ArgumentException("Flow document can have only one report header section");
if (listPageHeaders.Count == 1) _blockPageHeader = (SectionReportHeader)listPageHeaders[0];
ArrayList listPageFooters = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportFooter));
if (listPageFooters.Count > 1) throw new ArgumentException("Flow document can have only one report footer section");
if (listPageFooters.Count == 1) _blockPageFooter = (SectionReportFooter)listPageFooters[0];
_paginator = ((IDocumentPaginatorSource)_flowDocument).DocumentPaginator;
// remove header and footer in our working copy
Block block = _flowDocument.Blocks.FirstBlock;
while (block != null)
{
Block thisBlock = block;
block = block.NextBlock;
if ((thisBlock == _blockPageHeader) || (thisBlock == _blockPageFooter)) _flowDocument.Blocks.Remove(thisBlock);
}
// get report context values
_reportContextValues = _dynamicCache.GetFlowDocumentVisualListByInterface(typeof(IInlineContextValue));
FillData();
/*Application.Current.Dispatcher.Invoke(new Action(() =>
{
Window aa = new Window();
FlowDocumentPageViewer bb = new FlowDocumentPageViewer();
bb.Document = _flowDocument;
aa.Content = bb;
aa.SizeToContent = SizeToContent.WidthAndHeight;
aa.ShowDialog();
}));*/
}
示例13: PowerEntry
/// <summary>
/// Create a new <see cref="PowerEntry"/>. All arguments to this method are assumed
/// to be escaped for HTML already.
/// </summary>
/// <param name="heading">
/// The heading <see cref="Block"/>. This cannot be null.
/// </param>
/// <param name="flavorText">
/// The flavor text <see cref="Block"/>. This may be null.
/// </param>
/// <param name="detail">
/// The detail <see cref="Block"/>. This cannot be null.
/// </param>
/// <param name="modifierSource">
/// The <see cref="ModifierSource"/> that this <see cref="PowerEntry"/> was created for.
/// This may be null.
/// </param>
/// <exception cref="ArgumentNullException">
/// Only <paramref name="modifierSource"/> can be null.
/// </exception>
public PowerEntry(Block heading, Block flavorText, Block detail, ModifierSource modifierSource)
{
if (heading == null)
{
throw new ArgumentNullException("heading");
}
if (detail == null)
{
throw new ArgumentNullException("detail");
}
Heading = heading;
FlavorText = flavorText;
Detail = detail;
ModifierSource = modifierSource;
}
示例14: Accept
private bool Accept(Block block)
{
if (!TryMatch(block)) return false;
if (block is Table)
{
foreach (var inner in ((Table) block).RowGroups
.SelectMany(x => x.Rows)
.SelectMany(x => x.Cells)
.SelectMany(x => x.Blocks))
{
if (!Accept(inner)) return false;
}
return true;
}
if (block is Paragraph)
{
foreach (var inner in ((Paragraph) block).Inlines)
{
if (!TryMatch(inner)) return false;
}
return true;
}
if (block is BlockUIContainer)
{
// ignore children
return true;
}
if (block is List)
{
foreach (var inner in ((List) block).ListItems.SelectMany(listItem => listItem.Blocks))
{
if (!Accept(inner)) return false;
}
return true;
}
throw new InvalidOperationException("Unknown block type: " + block.GetType());
}
示例15: Clone
private Block Clone(Block block)
{
var paragraph = block as Paragraph;
if (paragraph != null)
{
var newParagraph = new Paragraph();
if (DependencyPropertyHelper.GetValueSource(paragraph, Paragraph.PaddingProperty).BaseValueSource != BaseValueSource.Default)
newParagraph.SetValue(Paragraph.PaddingProperty, paragraph.Padding);
if (DependencyPropertyHelper.GetValueSource(paragraph, Paragraph.MarginProperty).BaseValueSource != BaseValueSource.Default)
newParagraph.SetValue(Paragraph.MarginProperty, paragraph.Margin);
if (DependencyPropertyHelper.GetValueSource(paragraph, Paragraph.TextAlignmentProperty).BaseValueSource != BaseValueSource.Default)
newParagraph.SetValue(Paragraph.TextAlignmentProperty, paragraph.TextAlignment);
CopyProperties(paragraph, newParagraph);
foreach (var inline in paragraph.Inlines)
newParagraph.Inlines.Add(Clone(inline));
return newParagraph;
}
throw new NotSupportedException();
}