简体   繁体   English

如何将从Azure移动服务检索的数据动态绑定到GridView?

[英]How to bind data retrieved from Azure Mobile Services to GridView dynamically?

Using Azure Mobile Services to retrieve data from my Azure SQL DB, i would like to display those in my Employees gridview. 使用Azure移动服务从我的Azure SQL数据库检索数据,我想在“雇员”网格视图中显示这些数据。

Here is my XAML code : 这是我的XAML代码:

<GridView Name="Employees" SelectionMode="Single" Width="Auto" ItemContainerStyle="{StaticResource CustomGridViewItemStyle}" SelectionChanged="Employees_SelectionChanged">
    <GridViewItem Name="EmployeeNumber" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" Height="Auto" Margin="140,50,0,0">
        <StackPanel Name="ProfilePicAndDetails" Width="Auto" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,10,10">
            <Image  Name="ProfilePic" Source="Assets/profilepic.png"  Height="140" Width="140" HorizontalAlignment="Left" VerticalAlignment="Top"></Image>
            <StackPanel Name="Details" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" Margin="40,-10,0,0" Orientation="Vertical">
                <StackPanel Name="DisplayName" Orientation="Horizontal">
                    <TextBox Name="FirstName" FontSize="26" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                    <TextBox Name="LastName" FontSize="26" FontFamily="Segoe UI" Margin="-10,0,0,0" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                </StackPanel>
                <TextBox Name="Login" FontSize="18" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                <TextBox Name="Phone" FontSize="18" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                <TextBox Name="Mail" FontSize="18" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                <StackPanel Name="OtherDetails" Margin="-190,10,0,0">
                    <TextBox Name="Title" FontSize="18" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                    <TextBox Name="Department" FontSize="18" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                    <TextBox Name="Manager" FontSize="18" FontFamily="Segoe UI" IsReadOnly="True" Background="{x:Null}" Foreground="White" SelectionHighlightColor="{x:Null}" BorderBrush="{x:Null}"/>
                </StackPanel>
            </StackPanel>
        </StackPanel>
    </GridViewItem>
</GridView>

My code behind retrieving data : 我的数据检索背后的代码:

var GetEmployeesTable = App.MobileService.GetTable<GetEmployee>();
var FoundEmployees = await GetEmployeesTable.Where(g => g.givenName == GivenName && g.surname == SurName).ToListAsync();

I have 9 fieds in my DB : 我的数据库中有9种杂项:

givenName, surname, mail, phone, title, department, managerName, domainName, sAMAccountName. 给定名称,姓氏,邮件,电话,职务,部门,经理名称,域名,sAMAccountName。

The goal is to bind each of those fileds following this way : 目标是通过以下方式绑定每个这些文件:

  1. givenName (DB) -> FirstName (gridview) namedName(DB)-> FirstName(gridview)
  2. surname (DB) -> LastName (gridview) 姓(DB)->姓(gridview)
  3. ... (and so on) ... ... (等等) ...

I am successfully retrieving data from my Azure SQL DB using Azure Mobile Services but can't see how to bind them dynamically to my gridview. 我正在使用Azure移动服务从Azure SQL数据库成功检索数据,但是看不到如何将其动态绑定到我的gridview。

NB : I could have multiple employees to display (means multiple gridview items to create dynamically). 注意:我可能要显示多个员工(意味着要动态创建多个gridview项)。

You have to specify the binding for the Text property in XAML code. 您必须在XAML代码中为Text属性指定绑定。 Seems like you forgot this: Eg: 好像您忘记了这一点:例如:

 <TextBox Name="FirstName" Text="{Binding givenName}" 

Besides this you have to set the data source for your GridView. 除此之外,您还必须为GridView设置数据源。

Check out this post. 看看这篇文章。 It explains your scenario pretty good: http://debugmode.net/2013/04/11/fetching-windows-azure-mobile-services-data-in-xaml-based-windows-store-application/ 它很好地说明了您的情况: http : //debugmode.net/2013/04/11/fetching-windows-azure-mobile-services-data-in-xaml-based-windows-store-application/

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

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