如何将从Azure Mobile Services检索到的数据动态绑定到GridView
本文关键字:数据 动态绑定 GridView 检索 Services Azure Mobile | 更新日期: 2023-09-27 18:24:38
使用Azure移动服务从我的Azure SQL数据库中检索数据,我想在我的员工网格视图中显示这些数据。
这是我的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>
我检索数据背后的代码:
var GetEmployeesTable = App.MobileService.GetTable<GetEmployee>();
var FoundEmployees = await GetEmployeesTable.Where(g => g.givenName == GivenName && g.surname == SurName).ToListAsync();
我的数据库中有9个领域:
givenName、姓氏、邮件、电话、职务、部门、经理姓名、域名、sAMAccountName。
目标是按照以下方式绑定每个文件:
- givenName(DB)->FirstName(gridview)
- 姓氏(DB)->姓氏(gridview)
- 。。。(等等)
我使用Azure移动服务成功地从我的Azure SQL数据库中检索数据,但看不到如何将它们动态绑定到我的网格视图。
注意:我可以有多个员工来显示(意味着要动态创建多个网格视图项)。
您必须为XAML代码中的Text属性指定绑定。你好像忘了这个:例如:
<TextBox Name="FirstName" Text="{Binding givenName}"
除此之外,您还必须为GridView设置数据源。
看看这篇文章。它很好地解释了您的场景:http://debugmode.net/2013/04/11/fetching-windows-azure-mobile-services-data-in-xaml-based-windows-store-application/