0

我在设置枢轴控件中的 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>

我感谢任何帮助!

4

1 回答 1

0

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

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

于 2013-08-07T16:33:05.807 回答