如何将从 Azure 移动服务检索到的数据动态绑定到 GridView?
How to bind data retrieved from Azure Mobile Services to GridView dynamically?
使用 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, surname, mail, phone, title, department, managerName, domainName, sAMAccountName.
目标是按照以下方式绑定每个文件:
- givenName (DB) -> FirstName (gridview)
- 姓氏(数据库)-> 姓氏(网格视图)
- ...(依此类推)...
我正在使用 Azure 移动服务从我的 Azure SQL 数据库成功检索数据,但看不到如何将它们动态绑定到我的 gridview。
注意:我可以显示多个员工(意味着要动态创建多个 gridview 项目)。
您必须在 XAML 代码中指定文本 属性 的绑定。好像你忘了这个:
例如:
<TextBox Name="FirstName" Text="{Binding givenName}"
除此之外,您还必须为 GridView 设置数据源。
看看这个 post。它很好地解释了您的情况:
http://debugmode.net/2013/04/11/fetching-windows-azure-mobile-services-data-in-xaml-based-windows-store-application/
使用 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, surname, mail, phone, title, department, managerName, domainName, sAMAccountName.
目标是按照以下方式绑定每个文件:
- givenName (DB) -> FirstName (gridview)
- 姓氏(数据库)-> 姓氏(网格视图)
- ...(依此类推)...
我正在使用 Azure 移动服务从我的 Azure SQL 数据库成功检索数据,但看不到如何将它们动态绑定到我的 gridview。
注意:我可以显示多个员工(意味着要动态创建多个 gridview 项目)。
您必须在 XAML 代码中指定文本 属性 的绑定。好像你忘了这个: 例如:
<TextBox Name="FirstName" Text="{Binding givenName}"
除此之外,您还必须为 GridView 设置数据源。
看看这个 post。它很好地解释了您的情况: http://debugmode.net/2013/04/11/fetching-windows-azure-mobile-services-data-in-xaml-based-windows-store-application/