wp8.1 listview datatemplate with grid

时间:2015-10-05 13:38:53

标签: windows-phone-8.1

您好我有一个带有项目的datatemplate的列表视图                                 能见度="可见" ScrollViewer.VerticalScrollMode ="自动"                        高度=" {Binding ElementName = stck_main,Path = ActualHeight}"                          的SelectionChanged =" lst_OutletDetails_SelectionChanged">

                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Margin" Value="5,0,0,0" />
                        <!--<Setter Property="Background" Value="Green"/>
                        <Setter Property="Opacity" Value="0.8"/>
                        <Setter Property="Height" Value="80"/>-->
                    </Style>
                </ListBox.ItemContainerStyle>

                <ListBox.ItemTemplate>
                    <DataTemplate>


                        <StackPanel  Orientation="Horizontal" Height="100"  >
                            <Rectangle Fill="Orange" Width="5"/>
                            <Grid x:Name="grd_items_outletdetails" Background="{Binding ItemBackground}" Width="{Binding ElementName=lst_OutletDetails,Path=ActualWidth}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition ></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition ></RowDefinition>
                                    <RowDefinition ></RowDefinition>
                                    <RowDefinition ></RowDefinition>
                                </Grid.RowDefinitions>


                                <TextBlock Text="{Binding OutletName}" Margin="5,0,0,0"  Foreground="White" FontSize="22"  Grid.Row="0" />
                                <TextBlock Text="{Binding LastVisitedDate}"  VerticalAlignment="Center" Foreground="White" FontSize="18"
                                           Grid.Row="0" Margin="5,0,40,0"  HorizontalAlignment="Right" />


                                <TextBlock Text="{Binding OutletCode}" Foreground="White" Margin="5,0,0,0" FontSize="18"  HorizontalAlignment="Left" Grid.Row="1"/>

                                <StackPanel Orientation="Horizontal" Margin="5,0,20,0" Grid.Row="1"  HorizontalAlignment="Right">
                                <TextBlock Text="ISM:" Foreground="White" Margin="0,0,0,0" FontSize="18"  />
                                <TextBlock Text="{Binding ISMName}" Foreground="White" Margin="5,0,20,0" FontSize="18"  />
                                </StackPanel>

                                <TextBlock Text="{Binding Route}"  Margin="5,0,0,0" FontSize="18" Grid.Row="2" HorizontalAlignment="Left"  Foreground="White" />

                                <StackPanel Orientation="Horizontal"  Margin="5,0,20,0" Grid.Row="2"  HorizontalAlignment="Right">
                                  <TextBlock Text="Status:" Foreground="White" Margin="5,0,0,0" FontSize="18" ></TextBlock>
                                  <TextBlock Text="{Binding Status}" Foreground="White" Margin="5,0,20,0" FontSize="18"  />
                                </StackPanel>
                            </Grid>
                        </StackPanel>


                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

i want to change the colors of few items ,,, using mvvm pattern in windows phone 8.1

1 个答案:

答案 0 :(得分:0)

将您的问题(问题)置于代码块之外,现在已隐藏。 你究竟想做什么?是否要更改列表框中几个元素的背景颜色?更准确地描述它:)

我可以看到您将ItemBackground属性绑定到网格Background,因此只需更改源集合中所需的ItemBackground元素即可。