中存儲用戶控件我在寫一個Windows 8商店應用程序,並在其中設計了我自己的用戶控件。無法訪問Windows 8從代碼
這裏是我的用戶代碼(這是一個虛擬的控制,但這個存在的問題):
<UserControl
x:Class="Windows8StoreTest.TestUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="70"
Height="40">
<StackPanel>
<Button Content="Hello" Foreground="Pink" BorderBrush="Pink"/>
</StackPanel>
</UserControl>
我已經放棄了用戶控件到我的網頁,並給它一個名字:
<Page
x:Class="Windows8StoreTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:TestUserControl Name="testControl"/>
</Grid>
</Page>
但是,當我轉到後面的代碼時,我無法通過該名稱訪問該控件。它似乎並不存在!奇怪的是,該控件不存在於MainPage類的InitializeComponent()方法內,這就是它存在的原因。
我從用戶控件中遺漏了什麼?
我正在使用Windows 8 Store,XAML,c#。
在此先感謝
它應該工作。你能分享一些更多的信息來縮小這個問題嗎? –