locked
怎样动态改变LivstView中某一行Item的背景色?(注意:ListView中的Item是通过定义ItemTemplate和绑定数据来动态添加的。) RRS feed

  • 问题

  • xaml中定义了一个ListView  通过数据绑定和 LitstView.ItemTemplate 动态生成LivewView中的每一行。

    我希望能够使符合某个标准的某一行(Item)的背景色闪烁,但是不知道SotryBoard的TargetName该如何指定。

    xaml代码:

    <ListView>

                 <ListView.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="1270" Background="White">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="98"/>
                                    </Grid.RowDefinitions>
                                    <Grid Name="ListRow" Grid.Row="0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>

                                        <TextBlock Grid.Column="0" FontSize="40" Text="{Binding Name}"  Foreground="Green" />
                                        <Image Grid.Column="1" Source="{Binding imgSource}" HorizontalAlignment="Left" />
                                        <TextBlock Grid.Column="2" FontSize="40" Text="{Binding Confidence}"  Foreground="Green" />
                                    </Grid>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

    我曾经试图给每一行的Grid的Name属性绑定到一个不重复的标识,但是好像Name属性不能绑定,否则运行时出错。

    2014年3月1日 1:31