如何更改webview windows 8.1 app按钮单击页面

时间:2014-04-19 23:50:07

标签: c# xaml windows-8.1

我要做的是在由Windows应用商店的模板生成的空白页面上有一个webview。然后,当我单击一个按钮时,它会更改webview当前所在的页面。问题是,我不知道如何从代码隐藏中访问XAML变量来更改它。

<Page
x:Class="App6.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <WebView x:Name="browser"  Source="https://www.google.com/" HorizontalAlignment="Left" Height="224" Margin="463,237,0,0" VerticalAlignment="Top" Width="570"/>
    <Button Content="Button" HorizontalAlignment="Left" Margin="224,110,0,0" VerticalAlignment="Top"/>

</Grid>

我试过在C#代码中访问名称浏览器。但Visual Studio找不到它。我已经四处寻找了一下,但是我找不到很多这样的例子.... 我试图打开这个(http://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7)以获取如何使用它的示例。但这不会构建或使用Visual Studio 2013打开..

背后的代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?           LinkId=234238

namespace App6
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();

    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {

    }
}
}

1 个答案:

答案 0 :(得分:0)

执行类似

的操作
private void Button_Click(object sender, RoutedEventArgs e)
{
   browser.Navigate(new Uri(@"www.microsoft.com"));
}

browser是您的实际控制WebView