Browse Source

TextAlignment for TextBlock in FixedDocumentCreator.cs

pull/15/head^2
Peter Forstmeier 15 years ago
parent
commit
dca5f3553c
  1. 66
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/WPF/FixedDocumentCreator.cs
  2. 8
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/WpfReportViewer/WpfReportViewer.xaml

66
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/WPF/FixedDocumentCreator.cs

@ -7,6 +7,7 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers. * To change this template use Tools | Options | Coding | Edit Standard Headers.
*/ */
using System; using System;
using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
@ -16,6 +17,11 @@ using System.Windows.Media;
using ICSharpCode.Reports.Core.Exporter; using ICSharpCode.Reports.Core.Exporter;
using ICSharpCode.Reports.Core.Globals; using ICSharpCode.Reports.Core.Globals;
using Brush = System.Windows.Media.Brush;
using FontFamily = System.Windows.Media.FontFamily;
using Image = System.Windows.Controls.Image;
using Pen = System.Windows.Media.Pen;
using Size = System.Windows.Size;
namespace ICSharpCode.Reports.Core.WPF namespace ICSharpCode.Reports.Core.WPF
{ {
@ -254,10 +260,12 @@ namespace ICSharpCode.Reports.Core.WPF
TextBlock CreateTextBlock(ExportText exportText) TextBlock CreateTextBlock(ExportText exportText)
{ {
TextBlock textBlock = new TextBlock(); TextBlock textBlock = new TextBlock();
SetFont(textBlock, exportText.StyleDecorator); SetFont(textBlock, exportText.StyleDecorator);
textBlock.TextWrapping = TextWrapping.Wrap; textBlock.TextWrapping = TextWrapping.Wrap;
string [] inlines = exportText.Text.Split(System.Environment.NewLine.ToCharArray()); string [] inlines = exportText.Text.Split(System.Environment.NewLine.ToCharArray());
for (int i = 0; i < inlines.Length; i++) { for (int i = 0; i < inlines.Length; i++) {
if (inlines[i].Length > 0) { if (inlines[i].Length > 0) {
textBlock.Inlines.Add(new Run(inlines[i])); textBlock.Inlines.Add(new Run(inlines[i]));
@ -265,13 +273,65 @@ namespace ICSharpCode.Reports.Core.WPF
} }
} }
var li = textBlock.Inlines.LastInline; var li = textBlock.Inlines.LastInline;
textBlock.Inlines.Remove(li); textBlock.Inlines.Remove(li);
SetDimension(textBlock,exportText.StyleDecorator); SetDimension(textBlock,exportText.StyleDecorator);
textBlock.Background = ConvertBrush(exportText.StyleDecorator.BackColor);
SetContendAlignment(textBlock,exportText.StyleDecorator);
return textBlock; return textBlock;
} }
private void SetContendAlignment(TextBlock textBlock,TextStyleDecorator decorator)
{
switch (decorator.ContentAlignment)
{
case ContentAlignment.TopLeft:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Left;
break;
case ContentAlignment.TopCenter:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Center;
break;
case ContentAlignment.TopRight:
textBlock.VerticalAlignment = VerticalAlignment.Top;
textBlock.TextAlignment = TextAlignment.Right;
break;
// Middle
case ContentAlignment.MiddleLeft:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Left;
break;
case ContentAlignment.MiddleCenter:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Center;
break;
case ContentAlignment.MiddleRight:
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.TextAlignment = TextAlignment.Right;
break;
//Bottom
case ContentAlignment.BottomLeft:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Left;
break;
case ContentAlignment.BottomCenter:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Center;
break;
case ContentAlignment.BottomRight:
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
textBlock.TextAlignment = TextAlignment.Right;
break;
}
}
void SetFont(TextBlock textBlock, TextStyleDecorator styleDecorator) void SetFont(TextBlock textBlock, TextStyleDecorator styleDecorator)

8
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/WpfReportViewer/WpfReportViewer.xaml

@ -1,10 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<UserControl <UserControl
x:Class="ICSharpCode.Reports.Core.WpfReportViewer.WpfReportViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> x:Class="ICSharpCode.Reports.Core.WpfReportViewer.WpfReportViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid> <Grid>
<DocumentViewer <DocumentViewer
x:Name="DocumentViewer" x:Name="DocumentViewer"
Document="{Binding Path=DataContext.Document,&#xD;&#xA;&#x9;&#x9;&#x9;PresentationTraceSources.TraceLevel=High,&#xD;&#xA;&#x9;&#x9;&#x9;RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Document="{Binding Path=DataContext.Document,
PresentationTraceSources.TraceLevel=High,
RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
SnapsToDevicePixels="True"></DocumentViewer> SnapsToDevicePixels="True"></DocumentViewer>

Loading…
Cancel
Save