2013-04-24 19 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

相關問題