列表框项目不想拉伸

时间:2013-08-06 10:40:00

标签: .net windows-phone-7 windows-phone

我在旋转控件中设置listboxitem的样式有问题。我想拉伸它。我不确定我是否应该提及它因为它不应该对它产生影响,但是这个列表框是通过捕获滚动事件来动态填充的。我试过这个解决方案,但没有成功:

    <ListBox.ItemContainerStyle>
           <Style TargetType="ListBoxItem">
                 <Setter Property="HorizontalAlignment" Value="Stretch"/>
                 <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
           </Style>
</ListBox.ItemContainerStyle>

以下是整个pivotItem的代码:

<controls:PivotItem Header="Indeks">
            <Grid Name="grd_Content" HorizontalAlignment="Stretch" Background="Transparent">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>

                <ListBox x:Name="lbx_Index" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Foreground="White" Loaded="lbx_Index_Loaded" Template="{StaticResource ListBoxControlTemplate}" Grid.Row="1" Tap="lbx_Index_Tap" Background="{x:Null}">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ControlTemplate TargetType="ListBox">
                        <ScrollViewer x:Name="scrollViewer" 
                              BorderBrush="Transparent"
                              BorderThickness="0"
                              Background="MediumAquamarine"
                              Foreground="Transparent"
                              HorizontalAlignment="Stretch"       
                              Padding="{TemplateBinding Padding}"
                              Loaded="ScrollViewer_Loaded">
                            <ItemsPresenter HorizontalAlignment="Stretch"/>
                        </ScrollViewer>
                    </ControlTemplate>
                    <ListBox.DataContext>
                        <local:ListBoxPart/>
                    </ListBox.DataContext>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border x:Name="border" BorderBrush="Maroon" BorderThickness="2"
                            Padding="5" Margin="5" CornerRadius="4,4,4,4" HorizontalAlignment="Stretch">
                                <Grid HorizontalAlignment="Stretch">
                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="300*" />
                                        <ColumnDefinition Width="100*"/>
                                    </Grid.ColumnDefinitions>
                                    <!--<TextBlock Grid.Row="0" Grid.Column="0" TextAlignment="Center" TextTrimming="None" Text="Nazwa lekarstwa:" FontSize="14"/>-->
                                    <TextBlock Grid.Row="0" Grid.Column="0" TextAlignment="Left" TextTrimming="None" Text="{Binding Name}"/>
                                    <TextBlock Grid.Row="1" Grid.Column="0" TextAlignment="Left" TextTrimming="WordEllipsis"  Text="{Binding ActiveSubstance}" FontSize="12"/>
                                    <TextBlock Grid.Row="0" Grid.Column="1" TextAlignment="Left" Text="{Binding LevelOfPayment}"></TextBlock>
                                    <TextBlock Grid.Row="1" Grid.Column="1" TextAlignment="Left" Text="{Binding AidAmount}"></TextBlock>
                                </Grid>
                            </Border>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

                </ListBox>
            </Grid>


        </controls:PivotItem>

我随时提供帮助!

1 个答案:

答案 0 :(得分:0)

注意,您不需要将Horrizontal对齐设置设置为拉伸,除非它位于覆盖它的容器中。 默认情况下,大多数XAML控件都设置为占用最多空间。

同时检查您的边距是否没有将容器缩小到您想要的位置。 (注意你也可以使用负边距来拉伸)