2013-04-24 20 views
0

我对.NET很新,想用一个200x200的框架在Google里面做一个简单的XAML网页。我有一个XAML页面看起来像这样:如何在Silverlight XAML页面中为外部网页创建框架?

<UserControl x:Class="Oleo.CI.Content.IU.Form.Test" 
    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" 
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
    xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 
    xmlns:uiControl="clr-namespace:Oleo.CI.Contenidos.IU.Control;assembly=Oleo.CI.Contenidos.IU.Control" 
    mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="1002" Width="1002" Height="812" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"> 

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 10 18 -10"> 
      <navigation:Frame x:Name="Cont" Source="http://www.google.com" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Width="200" Height="200"/> 
      <TextBlock Text="Oferta" Grid.Column="3" Grid.Row="2" HorizontalAlignment="Right" /> 
    </StackPanel> 
</UserControl> 

我试图与这两个导航:框架和SDK:框架但框架是没有得到显示在页面上与代码(其他控件一样的TextBlocks工作RadGrids完美)。我不确定我做错了什么,任何人都可以透露我的一些想法吗?

谢谢

回答

0

您无法在Silverlight框架内打开网页。框架类代表支持导航到和从Silverlight页的控件。 您可以通过处理Frame的NavigationFailed事件来看到导航失败。

<navigation:Frame x:Name="Cont" Source="http://www.google.com" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Width="200" Height="200" 
      NavigationFailed="Cont_NavigationFailed"/> 

它会抛出异常,并显示消息:为URI 内容不能被加载。该URI可能无效。

更新: 您可以使用来自Html的iframe标记实现您的目标。

这就是你要做的: 在创建Silverlight应用程序时,Visual Studio会在你的解决方案中创建两个项目。一个用于生成.xap文件的Silverlight应用程序,以及一个默认包含TestPage.aspx的简单Asp.Net网站。您的.xap文件包含在此网页中,您的.xap的高度和宽度设置为100%。当然你可以根据需要选择它。目前我已将它设置为高度和宽度的50%。如果你要在浏览器的这个部分点击鼠标右键,你会看到Silverlight上下文菜单。在其他部分的web应用程序中,您将看到Html Web页面的默认上下文菜单。 所以你必须添加iframe标签到该页面。

<iframe src="http://www.msdn.com" height="700px" width="700px"></iframe> 
    <div id="silverlightControlHost"> 
     <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
      width="50%" height="50%"> 
      <param name="source" value="ClientBin/SilverlightApplication1.xap" /> 
      <param name="onError" value="onSilverlightError" /> 
      <param name="background" value="white" /> 
      <param name="minRuntimeVersion" value="5.0.61118.0" /> 
      <param name="autoUpgrade" value="true" /> 
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration: none"> 
       <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" 
        style="border-style: none" /> 
      </a> 
     </object> 
     <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; 
      border: 0px"></iframe> 
    </div> 

但是,我必须说你无法在iframe中打开google网站。因为谷歌阻止iframe。

+0

谢谢你的回答。那么我如何才能在Silverlight中实现我的目标并在框架上渲染Google? – 2013-04-24 15:15:10

+0

@DavidJiménezMartínez查看我的更新。另外不要忘记注册并将其标记为答案。 :) – 2013-04-24 15:46:18

相关问题