0

我有以下

g code

<GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.RowSpan="2"
            Padding="116,136,116,46"
            SelectionMode="Single"
            IsSwipeEnabled="false"
            Visibility="Collapsed">

            <GridView.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="DarkSeaGreen" BorderThickness="1">
                    <StackPanel HorizontalAlignment="Left" Width="250" Height="180" Background="SeaGreen">
                        <StackPanel VerticalAlignment="Top" >
                            <TextBlock Text="{Binding Name}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" TextWrapping="Wrap" MinHeight="40" FontSize="22"  Margin="15,10,15,0"/>
                        </StackPanel>

                        <Grid Height="Auto">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20*"/>
                                <RowDefinition Height="20*"/>
                                <RowDefinition Height="20*"/>
                                <RowDefinition Height="20*"/>
                                <RowDefinition Height="20*"/>

                             </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="150"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                                <TextBlock Grid.Row="0" Grid.Column="0"  Text="TotalMarks:" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,0,0"/>
                                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding TotalMarks}" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
                                <TextBlock Grid.Row="1" Grid.Column="0" Text="Total Questions:" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,0,0" />
                                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding TotalQuestions}" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" />
                                <TextBlock Grid.Row="2" Grid.Column="0" Text="Total attempts:" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"  Margin="15,0,0,0" />
                                <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding AttemptCount}" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"   />
                               <TextBlock Grid.Row="3" Grid.Column="0" Text="Ratings:" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,0,0" />
                                <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding TestRating}" Foreground="White" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" />
                            <!-- Here I want to add -->    

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

        </GridView>

我想在数据模板的网格中添加一个评级控件,以便它的值可以与一个整数变量绑定TestRating。由于我是数据绑定的新手,所以我不知道如何做到这一点。请提供一些帮助。

提前致谢。

4

2 回答 2

2

这可能取决于Rating您使用的控件。以下是使用Callisto's 的方法:

<callisto:Rating ItemCount="5" Value="{Binding TestRating}" />

假设绑定适用于TextBlock您要插入评分的位置的正上方,这也应该有效。

于 2013-01-11T19:50:41.380 回答
0

为了便于在源中反映任何更改,您需要进行双向绑定,以便将控件中所做的更改绑定回源。所以适当的改变是:

<callisto:Rating ItemCount="5" Value="{Binding TestRating, Mode=TwoWay}" />

于 2014-10-31T01:17:02.503 回答