0

将数据绑定到网格视图发现很困难

 if (response.StatusCode == HttpStatusCode.OK)
            {
                List<dashboard1> variable1 = new List<dashboard1>(); 
                var jsonString = await response.Content.ReadAsStringAsync();
                dynamic arr = JsonParser.Parse(jsonString);
                var items2 = arr[0].items; 
                foreach (var item3 in items2)
                {                      
                    variable1.Add(item3.sectionName);
                    variable1.Add(item3.procedureName);
                    variable1.Add(item3.reportName);
                    variable1.Add(item3.templateName);
                }
               itemGridView.ItemsSource = variable1;
            }

解析json并将其存储在列表中

现在我不知道如何将这些值绑定到用户界面请你帮我继续并将值传递给网格视图。

4

2 回答 2

0

您必须将类dashboard1的属性与 UI 控件绑定。假设您要显示所有属性,TextBlock然后将文本框的 text 属性与 class 的属性绑定dashboard1

所以代码会是这样的。

<TextBlock Text={Binding sectionName} />
于 2013-07-12T04:56:47.667 回答
0
 <GridView Grid.Row="2"
        x:Name="itemGridView"             

        SelectionMode="Multiple"                 
         SelectionChanged="itemGridView_SelectionChanged"      >



            <GridView.ItemTemplate >
                <DataTemplate >
                    <Border BorderThickness="1" BorderBrush="#7b579b" Tapped="Border_Tapped_1" >
                        <Grid Name="tile" Background="{Binding SubjectTilebackGround}" Height="150" Width="150" Tapped="tile_Tapped_1"  >
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="hello2" Text="{Binding SubjectName}" Foreground="White" FontSize="15" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="8"   FontWeight="ExtraLight" Visibility="{Binding isTopSubjectTextVisible}"/>
                            <TextBlock Text="{Binding SubjectName}" Foreground="White" FontSize="15" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="8" FontWeight="ExtraLight" Visibility="{Binding isBottomSubjectTextVisible}" />

                        </Grid>
                    </Border>
                </DataTemplate>
            </GridView.ItemTemplate>

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal" Margin="98,0,0,0"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate >
                        <DataTemplate >
                            <Grid Margin="0,0,0,6"  >
                                <Button
                                AutomationProperties.Name="Group Title"
                                Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding CategoryName}" Margin="2" FontSize="30" Foreground="White" FontWeight="Light" />
                                        <TextBlock Text="( 17 Apps )" Margin="10,2,2,2" FontSize="25" Foreground="White" FontWeight="ExtraLight" VerticalAlignment="Bottom" />
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid  Orientation="Vertical" Margin="0,0,80,0" MaximumRowsOrColumns="3"   />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>

在这个例子中,我添加了一些更有用的 gridview 属性。无论我在哪里使用过这样的绑定。

Background="{Binding SubjectTilebackGround}"

这意味着“SubjectTilebackGround”是您列出的对象的类中存在的一个属性..在您的情况下是 DASHBOARD1..所以您可以像我一样绑定它们的仪表板中可用的任何属性。希望这会有所帮助。

于 2013-07-12T05:30:25.467 回答