简体   繁体   English

将内容加载到WP8中的TextBox中

[英]Loading Contents into TextBox in WP8

I need to update the data on my server. 我需要更新服务器上的数据。

  • I need to GET the data 我需要GET数据
  • And need to store it in a TextBox 并需要将其存储在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 我可以从服务器GET数据,但无法在文本框中显示

MY in XAML code: 我的XAML代码:

<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: 我的示例JSON数据:

在此处输入图片说明

是否需要为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 您的xaml应该看起来像

<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; lstOrganisations.ItemSource = org;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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