- 자바스크립트의 모든 API를 클래스로 호출





[MainPage.xaml]


<UserControl x:Class="RiaJavaScript.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">

        <Grid.Resources>

            <Style x:Name="myButton" TargetType="Button">

                <Setter Property="Margin" Value="10"></Setter>

            </Style>

        </Grid.Resources>

        <Grid.RowDefinitions>

            <RowDefinition></RowDefinition>

            <RowDefinition></RowDefinition>

            <RowDefinition></RowDefinition>

        </Grid.RowDefinitions>

 

        <Button x:Name="btnAlert" Content="경고 대화상자" Style="{StaticResource myButton}" />

 

        <Button x:Name="btnConfirm" Content="확인 대화상자" Grid.Row="1" Style="{StaticResource myButton}" />

 

        <Button x:Name="btnDotNetKorea" Content="닷넷코리아로 이동" Grid.Row="2" Style="{StaticResource myButton}" />

 

    </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 RiaJavaScript

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            btnAlert.Click += new RoutedEventHandler(btnAlert_Click);

            btnConfirm.Click += new RoutedEventHandler(btnConfirm_Click);

            btnDotNetKorea.Click += new RoutedEventHandler(btnDotNetKorea_Click);

        }

 

        void btnDotNetKorea_Click(object sender, RoutedEventArgs e)

        {

            // window.location.href = 'url';

            HtmlWindow window = HtmlPage.Window;

            window.Navigate(new Uri("http://www.dotnetkorea.com"), "_blank");

        }

 

        void btnConfirm_Click(object sender, RoutedEventArgs e)

        {

            HtmlWindow window = HtmlPage.Window;

            if (window.Confirm("확인 또는 취소를 클릭"))

            {

                window.Alert("확인을 클릭하셨군요...");

            }

        }

 

        void btnAlert_Click(object sender, RoutedEventArgs e)

        {

            //[1] 실버라이트의 메시지박스

            MessageBox.Show("경고 대화상자");

            //[2] 실버라이트에서 자바스크립트의 window.alert() 함수 호출

            HtmlWindow window = HtmlPage.Window;

            //[3] window개체의 모든 명령어 호출

            window.Alert("경고 대화상자");

        }

    }

}

 

 


















Posted by holland14
: