簡體   English   中英

無法訪問Windows Phone 8.1中的集線器內的元素

[英]Can't access elements inside the Hub in Windows Phone 8.1

我一直在嘗試訪問在應用程序的集線器內部創建的某些元素,但是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);

我該如何解決? 提前致謝!

不幸的是,Microsoft決定您必須通過DataTemplate定義HubSection的內容,而不是直接將其作為Content放置。 這意味着您不能使用控件的名稱直接訪問它。

在此處查看更多信息: 如何訪問Windows 8.1存儲區中Hubsection Datatemplate內部的任何控件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM