C# Can';t在Windows Phone 8.1中访问集线器内的元素
我一直在尝试访问在我的应用程序的中心内创建的一些元素,但是IDE说名称C# Can';t在Windows Phone 8.1中访问集线器内的元素,c#,xaml,windows-phone-8.1,C#,Xaml,Windows Phone 8.1,我一直在尝试访问在我的应用程序的中心内创建的一些元素,但是IDE说名称user\u Image在当前上下文中不存在user\u Image是我试图在中心内访问的元素 我该怎么做 XAML: <Hub x:Name="centralHub" Header="bacpac" HorizontalAlignment="Left" Height="658" Margin="-7,27,-55,-18" VerticalAlignment="Top" Width="462">
user\u Image
在当前上下文中不存在user\u Image
是我试图在中心内访问的元素
我该怎么做
XAML:
<Hub x:Name="centralHub" Header="bacpac" HorizontalAlignment="Left" Height="658" Margin="-7,27,-55,-18" VerticalAlignment="Top" Width="462">
<Hub.Background>
<ImageBrush Stretch="UniformToFill" ImageSource="ms-appx:///Images/Panorama.png"/>
</Hub.Background>
<HubSection x:Name="homeSection" Header="Home">
<DataTemplate>
<Grid HorizontalAlignment="Left" Height="518" Margin="-9,-32,0,-3" VerticalAlignment="Top" Width="425">
<TextBlock x:Name="Hello_Label" HorizontalAlignment="Left" Height="109" Margin="10,0,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" FontSize="60" RenderTransformOrigin="-0.894,0.523" FontFamily="Segoe WP Light">
<Run Text="Hello"/>
</TextBlock>
<Image x:Name="user_Image" HorizontalAlignment="Left" Height="100" Margin="152,109,0,0" VerticalAlignment="Top" Width="100"/>
<TextBlock x:Name="user_Name" HorizontalAlignment="Left" Margin="10,223,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top" FontSize="26" Width="370"/>
Task.Factory.StartNew(() =>
{
var profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", fbSession.Token.FacebookId, "square", fbSession.Token.AccessToken);
user_Image.Source = new BitmapImage(new Uri(profilePictureUrl));
user_Name.Text = String.Format("{0} {1}", (string)result["first_name"], (string)result["last_name"]);
}, new System.Threading.CancellationToken(), TaskCreationOptions.PreferFairness, UISyncContext);
我该如何解决这个问题?提前谢谢 不幸的是,Microsoft决定您必须通过
DataTemplate
定义HubSection
的内容,而不是直接将其作为content
。这意味着您不能使用控件的名称直接访问它
请参阅此处的更多信息: