简体   繁体   中英

Loading Contents into TextBox in WP8

I need to update the data on my server.

  • I need to GET the data
  • And need to store it in a TextBox
  • Then I need to perform my Update operation.

I'm able to GET the data from server but unable to display it in the text box

MY in XAML code:

<Grid x:Name="ContentPanel" Margin="12,157,12,4" Grid.RowSpan="2">
    <TextBlock HorizontalAlignment="Left" Height="30" Margin="20,67,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top" Width="65"/>
    <TextBox x:Name="txt_name" HorizontalAlignment="Left" Height="73" Margin="121,42,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="315" BorderThickness="0" InputScope="PersonalFullName"/>
</Grid>

My code to retrieve data from server on page load:

private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    String OrganizationResult;
    if (NavigationContext.QueryString.ContainsKey("selectedItem"))
    {
        OrganizationResult = NavigationContext.QueryString["selectedItem"];
        string[] content = OrganizationResult.Split(',');
        string value = content[0];
        String id = value.Replace("{ id = ", "");
        Organization[] org;
        org = await client.searchOrganizationdetails(id);

        if (org != null)
        {
            var query = from c in org
                        select new
                        {
                            // Need to display the contents in textbox
                            // Eg:txt_name.Text=c.name
                        };
        }
    }
}

My sample JSON data:

在此处输入图片说明

是否需要为LINQ查询里面 ?我不认为你可以做到这一点?

If you need to bind to a list

Assuming you collection is of the type

public class Organization
{
    public string Name { get; set; }
    public string Address { get; set; }
}

Your xaml should look like

<ListBox x:Name="lstOrganisations">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Name}" />
                    <TextBox Text="{Binding Address}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Bind with

lstOrganisations.ItemSource = org;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM