2013-08-06 68 views
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任何幫助!

+1

你的列表框左對齊,從列表框中移除下列xaml:Horizo​​ntalAlignment =「Left」 –

回答

0

請注意,您不需要設置Horrizontal對齊設置爲伸展,除非它位於覆蓋它的容器中。 默認情況下,大多數XAML控件都設置爲佔用最多空間。

還要檢查您的保證金是否不會將您的容器縮小到您想要的位置以下。 (注意你也可以使用負邊距來延伸)