Windows中的评级控制存储应用程序并将整数值绑定到它

时间:2013-01-10 06:20:38

标签: xaml data-binding winrt-xaml windows-store-apps

我有以下

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绑定。由于我是数据绑定的新手,我不知道如何做到这一点。请提供一些帮助。

提前致谢。

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:0)

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

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