2014-02-25 18 views
1

在我需要的情況下改變這種是否可以從C#代碼編輯MainPage.xaml?

<DrawinSurfaceBackgroundGridgx:Name="DrawingSurfaceBackground"Loaded="DrawingSurfaceBackground_Loaded"> 
</DrawingSurfaceBackgroundGrid> 

這個

<Grid> 
<phone:WebBrowser Name="MiniBrowser" Visibility="Collapsed"/> 
<!--LayoutRoot is the root grid where all page content is placed--> 
<DrawingSurfaceBackgroundGridx:Name="DrawingSurfaceBackground"Loaded= 
    "DrawingSurfaceBackground_Loaded"> 
    </DrawingSurfaceBackgroundGrid> 
</Grid> 

當unity3d構建默認的項目有一個默認的MainPage。我需要在unity3d插件的主頁上添加一個webbrowser組件。然後我需要調用瀏覽器導航並訂閱一些瀏覽器事件,如loadCompleted可能嗎?請給我舉個例子

+1

你的問題似乎不完整。你能提供關於你想要做什麼的更多細節嗎? – Alan006

+0

爲什麼不在xaml中而是在運行時執行此操作?我們有描述如何從Unity引發事件並將它們放入xaml/c#項目一側的文檔:unity3d.com/pages/windows/porting –

回答

2

你可以通過編程獲得添加/刪除項目。如果你可以訪問MainPage類,你可以得到它的內容,這是網格,它的子元素是實現IList的UIElementCollection。

IList中有一個插入方法,它允許你在一個指定索引插入一個元素,你的情況爲0,在這裏一個完整的例子:

MainPage mainPage = new MainPage(); 
var miniBrowser = new WebBrowser 
{ 
    Visibility = Visibility.Collapsed;  
}; 
mainPage.Content.Children.Insert(0, miniBrowser); 

我沒有名字的web瀏覽器類,因爲加因爲它是以編程方式添加的,所以它確實沒有什麼區別(在設計時使用Name屬性(在設計時和在運行時解析xaml [在InitializeComponent方法中))在部分類中生成一個屬性(MainPage.igcs /MainPage.g.cs))。

您掌握MainPage的方式通常是從Application.Current.Content(Application.Current將包含一個Frame,其內容是MainPage)。

相關問題