Trying to set up a simple print page. Simple for now anyway.
I am trying to get a writeablebitmap from the map, which I can do. I've created a very simple page and it gets an image of the map and prints just fine. The problem is the image is always clipped on the right side of the printed page, I assume because my map is larger than the writeablebitmap.
Here is the code as it stands now:
Private Sub doc_PrintPage(sender As Object, e As PrintPageEventArgs)
' Method1 - works fine but is clipped on the right side.
Dim mapBM As WriteableBitmap = New WriteableBitmap(myMap, New TranslateTransform())
'Method 2 - manually set the size, produces no errors but has no map image
' Dim mapBM As WriteableBitmap = New WriteableBitmap(1300, 768)
' mapBM.Render(myMap, New TranslateTransform())
Dim mapImage As Image = New Image()
With mapImage
.Source = mapBM
.Stretch = Stretch.None
End With
Dim mapVB As Viewbox = New Viewbox
With mapVB
.MaxHeight = 450
.MaxWidth = 675
.StretchDirection = StretchDirection.DownOnly
.Stretch = Stretch.UniformToFill
.Child = mapImage
End With
Dim printMapBorder As Border = New Border
With printMapBorder
.HorizontalAlignment = Windows.HorizontalAlignment.Center
.VerticalAlignment = Windows.VerticalAlignment.Center
.BorderBrush = New SolidColorBrush(Colors.Black)
.BorderThickness = New Thickness(0.5)
.CornerRadius = New CornerRadius(8.0)
'end border
.Height = 465
.Width = 690
.Margin = New Thickness(5, 10, 5, 20)
End With
mapVB.Child = mapImage
printMapBorder.Child = mapVB
Dim printStack As StackPanel = New StackPanel
printStack.Orientation = Orientation.Vertical
Dim titleTB As TextBox = New TextBox
With titleTB
.TextAlignment = TextAlignment.Center
.FontSize = 16
End With
titleTB.Text = "Test Map"
printStack.Children.Add(titleTB)
printStack.Children.Add(printMapBorder)
e.PageVisual = printStack
e.HasMorePages = False
End Sub
Any ideas as to why I get no image when I use method 2?
Thanks for any help you can give.