2017년 1월 25일 수요일

자마린 스튜디오(Xamarin)을 사용한 웹뷰 컨트롤 제어 코드입니다.

맥에서 C#으로 아이폰용앱, 안드로이드용 앱을 만드는 것은 꿈만 같은 일입니다. ^^

맥에서 자마린 스튜디오로 자마린폼기반으로 프로젝트를 생성합니다. 아래와 같이 재물 코드를 코딩합니다.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
x:Class="DemoDataBinding.DemoWebView">


<ContentPage.Padding>    
<OnPlatform x:TypeArguments="Thickness"        
  iOS="10, 20, 10, 0"        Android="10, 0"        WinPhone="10, 0" />    
</ContentPage.Padding>


<StackLayout>        
<Entry Keyboard="Url"            Placeholder="web address"            
Completed="OnEntryCompleted" />        
  <StackLayout Orientation="Horizontal"            
  BindingContext="{x:Reference webView}">            
<Button Text="&#x21D0;"                FontSize="Large"                
HorizontalOptions="FillAndExpand"                
IsEnabled="{Binding CanGoBack}"                Clicked="OnGoBackClicked" />            
<Button Text="&#x21D2;"                FontSize="Large"                
HorizontalOptions="FillAndExpand"                IsEnabled="{Binding CanGoForward}"                Clicked="OnGoForwardClicked" />            
</StackLayout>                         

<WebView x:Name="webView"                VerticalOptions="FillAndExpand"                 
Source="https://xamarin.com" />    
</StackLayout>
</ContentPage>

using System.Collections.Generic;
using Xamarin.Forms;
namespace DemoDataBinding
{
    public partial class DemoWebView : ContentPage
    {
        public DemoWebView()
        {
            InitializeComponent();
        }
        void OnEntryCompleted(object sender, EventArgs args)
        {
            webView.Source = ((Entry)sender).Text; 
        }
        void OnGoBackClicked(object sender, EventArgs args)
        {
            webView.GoBack(); 
        }
        void OnGoForwardClicked(object sender, EventArgs args)
        {
            webView.GoForward(); 
        }
    }
}



using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace DemoDataBinding
{
    public partial class DemoWebView : ContentPage
    {
        public DemoWebView()
        {
            InitializeComponent();
        }

        void OnEntryCompleted(object sender, EventArgs args)
        {
            webView.Source = ((Entry)sender).Text; 
        }

        void OnGoBackClicked(object sender, EventArgs args)
        {
            webView.GoBack(); 
        }

        void OnGoForwardClicked(object sender, EventArgs args)
        {
            webView.GoForward(); 
        }
    }
}

실행하면 아래와 같이 실행됩니다.




댓글 없음:

댓글 쓰기

참고: 블로그의 회원만 댓글을 작성할 수 있습니다.

테슬라 차량이 무인 배송이 된 역사적인 사건입니다. ㅎㅎ

테슬라는 꿈을 그리는 기업입니다. 좀 황당하고 무섭기도 한데 시간이 지연되고 있지만 꾸준하게 발전하는 모습을 보여줍니다.  테슬라 차량을 주문한 고객이 무인 배송으로 차를 받는 영상입니다. ㅋㅋ  이러다가 정말 화성 탐사선에 옵티머스 로봇이 탑재되는 ...