我在訪問一個頁面的XAML定義的面板控制問題訪問XAML控件,XAML的定義是這樣的:Silverlight的:從代碼
<UserControl
x:Class="PhoneBook.SilverlightMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d" Width="400" Height="300" d:DesignWidth="993" d:DesignHeight="887">
<Grid x:Name="LayoutRoot" />
</UserControl>
類的定義是這樣的:
public partial class SilverlightMainPage : UserControl
{
public SilverlightMainPage()
{
InitializeComponent();
}
}
而且我想這種方式實例化它:
var silverlightMainPage = new PhoneBook.SilverlightMainPage();
SomeMethod((silverlightMainPage.LayoutRoot);
我感到奇怪的是,當我把點AFTE對象實例,它實際上列出了作爲其中一個成員的LayoutRoot,但是當我嘗試編譯該應用程序時,它說沒有該名稱的成員。
任何想法可以發生什麼?
感謝
編輯:我也嘗試創建對返回的LayoutRoot元素SilverlightMainPage類的屬性,但它也說,類不包含佈局根的定義。
嘗試右鍵單擊InitializeComponent()方法,然後選擇「轉到定義」。你看到LayoutRoot嗎? –
該面板無法訪問到哪裏?你在哪裏設置主頁面?從App.xaml?你能提供SomeMethod()的代碼嗎? – danbord