1

I've been trying to access some elements created inside the Hub in my app but the IDE says The name user_Image does not exist in the current context. user_Image is the element that I'm trying to access inside the hub.

How do I do this?

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# Code:

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

How do I fix this? Thanks in advance!

amiry jd
  • 27,021
  • 30
  • 116
  • 215
Nimila Hiranya
  • 4,842
  • 10
  • 35
  • 52

1 Answers1

2

Unfortunately, Microsoft decided that you have to define the content of HubSection via DataTemplate instead of putting it directly as Content. The implication is you cannot use the name of the control to access it directly.

See more here: How to access any control inside Hubsection Datatemplate in Windows 8.1 store

Community
  • 1
  • 1