Print Button

1060
5
05-25-2010 04:38 AM
jonataspovoas
New Contributor III
Hi, I'm doing a Silverlight application in C #. Net that show and navigates a map.

I'm having trouble creating a button that prints the current layer of the map shown on the screen.

In Xaml, the button code is as follows:

<button X:Name="Print" Style="{StaticResource MenuButtonStyle}" Click="BtnPrint_click" Width="40" Height="35"
    Margin="5" ToolTipService.ToolTip="Imprimir">
    <image Source="Images/i_print.png" />
</ Button>

This button calls the function "BtnPrint_click" which is implemented in Mainpage.xaml.cs and should open the print menu.
0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor
And what's the code in your BtnPrint click handler?
Also see the print section in my blogpost here: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/05/04/Take-advantage-of-new-Silverlight-...
0 Kudos
jonataspovoas
New Contributor III
Hi, your blogpost helped, but I still can not print the current map layer on the page. Part of the map is outside the printable area, and I can't include more information like s a header or scale.

This is the current code btnClick:

private void BtnPrint_click (object sender, RoutedEventArgs e)
{
            imprime.BeginPrint + = (s, args) =>
            {
                / / Here should show message "busy" or "printing"
            };
            imprime.PrintPage + = (s, args) =>
            {
                args.PageVisual = this.Mapa;
                args.HasMorePages = false, / * 1 * /
            };
            imprime.EndPrint + = (s, args) =>
            {
                / / Hide message here is "busy" or "imprinting," or switch to printing completed
            };
            imprime.Print (Digital Map of Salvador ");
}
0 Kudos
dotMorten_esri
Esri Notable Contributor
In that case don't print the map, but print a control that contains a map plus header etc.
0 Kudos
LucasCulbertson
New Contributor
Morten,

I just moved my applications over to SL4 and the new ESRI API, but I'm a little disappointed with Microsoft's first stab at printing capabilities.  I'm trying to do something very simple with my map document.  I want the user to be able to print a screenshot of the UIelement that contains all of my controls (legend, layer list, map, etc.,) but I'm having a hard time getting the control to resize to fit the page and to print in landscape orientation.  I figured Microsoft would have added in a fit to page method or something similar but not for this first version apparently.  Any help would be much appreciated!

Lucas Culbertson
0 Kudos
dotMorten_esri
Esri Notable Contributor
I can only agree that the print solution in SL4 is not perfect. It will get you further than with SL3, but it's definitely not a full print story (yet). We have been very vocal to Microsoft about this.

The easiest way is to create a separate usercontrol that represents your entire layout (it should resize and reflow as you change the control size), and then load a map into that. You then just print that usercontrol instance.
0 Kudos