在 WP8 中将内容加载到 TextBox [英] Loading Contents into TextBox in WP8

查看:24
本文介绍了在 WP8 中将内容加载到 TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新我服务器上的数据.

I need to update the data on my server.

  • 我需要GET数据
  • 并且需要将其存储在 TextBox 中
  • 然后我需要执行更新操作.

我能够GET来自服务器的数据,但无法在文本框中显示

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

MY 在 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>

我在页面加载时从服务器检索数据的代码:

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

我的示例 JSON 数据:

推荐答案

如果需要绑定到列表

假设你的集合是这样的

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

你的 xaml 应该看起来像

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>

绑定

lstOrganisations.ItemSource = org;

lstOrganisations.ItemSource = org;

这篇关于在 WP8 中将内容加载到 TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆