我有以下
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
绑定。由于我是数据绑定的新手,我不知道如何做到这一点。请提供一些帮助。
提前致谢。
答案 0 :(得分:2)
这可能取决于您使用的Rating
控件。以下是Callisto's:
<callisto:Rating ItemCount="5" Value="{Binding TestRating}" />
假设绑定适用于您要插入评级的位置正上方的TextBlock
,这也应该有效。
答案 1 :(得分:0)
为了便于在源中反映任何更改,您需要双向绑定,以便将控件中所做的更改绑定回源。所以适当的改变是:
<callisto:Rating ItemCount="5" Value="{Binding TestRating, Mode=TwoWay}" />
&#13;