Loading Contents into TextBox in WP8

2019-08-31 14:09发布

问题:

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:

回答1:

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;



回答2:

Does it need to be inside the LINQ query?I don't think you can do that...