【问题标题】:Can't access elements inside the Hub in Windows Phone 8.1在 Windows Phone 8.1 中无法访问集线器内的元素
【发布时间】:2015-04-20 18:12:24
【问题描述】:

我一直试图在我的应用程序中访问在 Hub 内创建的一些元素,但 IDE 显示名称 user_Image 在当前上下文中不存在。 user_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"/>

C# 代码:

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);

我该如何解决这个问题?提前致谢!

【问题讨论】:

    标签: c# xaml windows-phone-8.1


    【解决方案1】:

    不幸的是,微软决定你必须通过DataTemplate 定义HubSection 的内容,而不是直接把它作为Content。这意味着您不能使用控件的名称直接访问它。

    在此处查看更多信息:How to access any control inside Hubsection Datatemplate in Windows 8.1 store

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多