2012-08-01 132 views
0

我試圖在屏幕上的包裝面板上動態顯示按鈕,以便它們在沒有任何滾動條的情況下很好地放置。我有如下的標記,但滾動條出於某種原因。我們如何讓滾動條不出現,按鈕佈局沒有任何滾動條。在wrappanel中添加動態按鈕wpf

<ListBox x:Name="ItemsListBox" > 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <ToggleButton Content="{Binding Name}" Click="Click" MinWidth="120" MinHeight="70" FontWeight="Bold" FontSize="18"/> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <WrapPanel></WrapPanel> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
     </ListBox> 

回答

0

添加

ScrollViewer.VerticalScrollBarVisibility="Hidden" 
ScrollViewer.HorizontalScrollBarVisibility="Hidden" 

到你的容器。

2

你的ListBox裏面有什麼控件?大多數情況下,您所描述的問題是由允許ListBox增長的父母造成的。

您可以通過在ListBox上設置明確的Width="200"並測試會發生什麼來證明這是否是問題。如果它包裝,那麼問題是ListBox的父母。

+0

滾動條仍然出現 – TrustyCoder 2012-08-01 15:43:31

0

這就是我試圖實現的。

<ItemsControl x:Name="ListBox" Grid.Row="5" Grid.ColumnSpan="2"> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <WrapPanel Orientation="Vertical"/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
         <ToggleButton Content="{Binding Name}" MinWidth="120" MinHeight="50" FontWeight="Bold" FontSize="16" Margin="5"/> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
      </ItemsControl>