2012-10-22 28 views
0

我在我的網格的第三列中有Itemscontrol,它顯示了一些動態加載的按鈕組。 我希望這些內容(即按鈕)佔據網格的最大寬度。當內容超出網格大小時,它將顯示垂直滾動條。滾動條在網格的ItemsCotrol上出現錯誤

我申請滾動條風格的ItemsControl如下:

<Style x:Key="ItemControlStyle" TargetType="{x:Type ItemsControl}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type ItemsControl}"> 
         <Border> 
          <ScrollViewer HorizontalContentAlignment="Stretch" 
              CanContentScroll="True" 
              HorizontalScrollBarVisibility="Disabled" 
              Uid="ScrollViewer_9" 
              VerticalScrollBarVisibility="Auto"> 
           <ItemsPresenter Margin="{TemplateBinding Padding}" 
               KeyboardNavigation.DirectionalNavigation="Cycle" 
               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
               Uid="ItemsPresenter_5" /> 
          </ScrollViewer> 
         </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

我也申請的Horizo​​ntalAlignmentVerticalAllignMent爲「拉伸」兩個ItemsControl的以及其母公司,即電網。

輸出看法我想是(網格的第三列) enter image description here

輸出我得到的是: enter image description here

滾動條的大小之後應該出現超過 如何將這些內容水平調整到網格的最大寬度?

+0

難道僅僅是增加的Horizo​​ntalAlignment =拉伸到ScrollViewer中的情況? – GazTheDestroyer

+0

對不起,我不明白你在問什麼。但讓我告訴你我想要的是,ItemsControl中的這些按鈕被固定到單個'行'(如第二張圖)。我希望內容佔據整個列的寬度,然後在內容數超過列大小的情況下使其滾動。讓我把另一個圖像顯示在滾動條應該出現之後。 – deathrace

+0

已經用我的意思添加了答案 – GazTheDestroyer

回答

1

難道只是加入HorizontalAlignment=StretchScrollViewer

即:

<Style x:Key="ItemControlStyle" TargetType="{x:Type ItemsControl}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ItemsControl}"> 
       <Border> 
        <ScrollViewer HorizontalAlignment="Stretch" 
            HorizontalContentAlignment="Stretch" 
            CanContentScroll="True" 
            HorizontalScrollBarVisibility="Disabled" 
            Uid="ScrollViewer_9" 
            VerticalScrollBarVisibility="Auto"> 
         <ItemsPresenter Margin="{TemplateBinding Padding}" 
             KeyboardNavigation.DirectionalNavigation="Cycle" 
             SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
             Uid="ItemsPresenter_5" /> 
        </ScrollViewer> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

嘗試了這一點,但仍然獲得相同的'輸出我得到'的形象。但是在做這件事的時候,我碰到了把物品放在包裝紙上。我將包裝面板的尺寸增加到了我按鈕模板的2倍寬度。現在我得到了我所期望的,但沒有使用scrollBar。如果我使用滾動條,那麼它再次提供錯誤的輸出 – deathrace