- 실버라이트에서 제공하지 않는 인쇄기능을 자바스크립트를 호출해서 사용
    - Silverlight 4.0에서는 인쇄기능 제공 예정






[MainPage.xaml]


<UserControl x:Class="RiaPrint.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel>

            <TextBlock x:Name="title" Text="현재 페이지 인쇄"></TextBlock>

            <Button x:Name="btnPrint" Content="인쇄"></Button>

        </StackPanel>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Browser;

 

namespace RiaPrint

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            btnPrint.Click += new RoutedEventHandler(btnPrint_Click);

        }

 

        void btnPrint_Click(object sender, RoutedEventArgs e)

        {

            // 실버라이트에서 자바스크립트의 print 기능 실행

            HtmlWindow window = HtmlPage.Window;

            window.Invoke("print", new object[] { });

        }

    }

}

 

 







[실행결과]











Posted by holland14
: