0
我有問題與我的列表控件中的listboxitem樣式。我正試圖伸展它。我不知道我應該提及它,因爲它不應該對它產生影響,但是這個列表框是通過捕獲滾動事件來動態填充的。 I`ve嘗試這種解決方案,但都沒有成功:列表框項目不想伸展
<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>
我apperciate任何幫助!
你的列表框左對齊,從列表框中移除下列xaml:HorizontalAlignment =「Left」 –