2012-02-14 50 views
1
垂直滚动的一个ComboBox内

请大师们,我在我的WPF aplication ComboBox,并能够添加包含的CheckBox到他们列表框,使用户可以选择从类别中的多个项目。但现在的问题我有是:如何使一个列表框在WPF

**,因为他们拒绝了,尽管高度设置为Auto是滚动的列表框无法显示全部的复选框。

在此先感谢您的时间在考虑这个问题

* 下面的造型是S由于火焰的步骤适用于其他*

  <ComboBox Height="23" HorizontalAlignment="Left" Margin="20,10,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" Text="Hamburger & Sandwiches" StaysOpenOnEdit="True"> 

    <ListBox BorderThickness="0,0,2,0" ScrollViewer.VerticalScrollBarVisibility="Visible" 
       SelectionMode="Multiple" Background="#E3418D00" Focusable="False" SnapsToDevicePixels="True"> 
        <ListBox.BorderBrush> 
        <SolidColorBrush /> 
       </ListBox.BorderBrush> 
       <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Chicken Wrap" ClickMode="Release" BorderBrush="#FFF58B09" Name="chkChickenWrap"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkRibeyeSteakWrap" Content="Ribeye Steak Wrap" FontFamily="Lucida Sans" Foreground="Cyan" BorderBrush="Orange"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkShreddedBeefWrap" Foreground="Cyan" FontFamily="Lucida Sans" Content="Shredded Beef Wrap" BorderBrush="Orange"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkCheeseburgerParadiseWrap" Foreground="Cyan" FontFamily="Lucida Sans" BorderBrush="Orange" Content="Cheeseburger Paradise Wrap"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkVeggieWrap" BorderBrush="Orange" Content="Veggie Wrap" Foreground="Cyan" FontFamily="Lucida Sans"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkChiliBurger" Foreground="Cyan" FontFamily="Lucida Sans" Content="Chili Burger" BorderBrush="Orange"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkTiajuanaTorpedo" BorderBrush="Orange" Content="Tiajuana Torpedo" FontFamily="Lucida Sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Stuffed Burger" BorderBrush="Orange" Name="chkStuffedBurger"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkCheeseBurger" BorderBrush="Orange" Content="Cheese Burger" Foreground="Cyan" FontFamily="Lucida Sans"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Patty Melt" BorderBrush="Orange" Name="chkPattyMelt"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Harry's Big Barn Burger" BorderBrush="Orange" Name="chkHarrysBigBarnBurger"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkTheReuban" BorderBrush="Orange" Content="The Reuban" FontFamily="Lucida Sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkBBQBeefSandwich" Foreground="Cyan" FontFamily="Lucida Sans" Content="BBQ Beef Sandwich" BorderBrush="Orange"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkSteakSandwich" BorderBrush="Orange" Content="Steak Sandwich" FontFamily="Lucida Sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkFrenchDip" BorderBrush="Orange" Content="French Dip" FontFamily="Lucid sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Chili Dog" BorderBrush="Orange" Name="chkChiliDog"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkChickenFriedSteakSandwich" BorderBrush="Orange" Content="Chicken Fried Steak Sandwich" FontFamily="Lucida Sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkClubSandwich" BorderBrush="Orange" Content="Club Sandwich" Foreground="Cyan" FontFamily="Lucida Sans"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkCajunCatfishSandwich" Foreground="Cyan" FontFamily="Lucida Sans" Content="Cajun Catfish Sandwich" BorderBrush="Orange"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkEggAndCucumberTeaSandwich" BorderBrush="Orange" Content="Egg &amp; Cucumber Tea Sandwiches" FontFamily="Lucid sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
       <CheckBox Name="chkSmokedSalmonCrosini" BorderBrush="Orange" Content="Smoked Salmon Crosini Recipe" FontFamily="Lucida Sans" Foreground="Cyan"> 
        <CheckBox.Background> 
         <SolidColorBrush /> 
        </CheckBox.Background> 
       </CheckBox> 
      </ListBox> 
     </ComboBox> 

回答

1

使用的ScrollViewer的CombBoxes之一。

把你所有的滚动控制内部的ScrollViewer。

1

为了垂直滚动你可能要指定项目面板中的最大高度列表框项目。

这段代码会做你想要什么:

<ComboBox Height="23" HorizontalAlignment="Left" Margin="20,10,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" Text="Hamburger and Sandwiches"> 
    <ListBox BorderThickness="0,0,2,0" ScrollViewer.VerticalScrollBarVisibility="Visible" 
     SelectionMode="Multiple" Background="#E3418D00" Focusable="False" SnapsToDevicePixels="True"> 

     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Vertical" MaxHeight="200"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 

     <ListBox.BorderBrush> 
      <SolidColorBrush /> 
     </ListBox.BorderBrush> 
     <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Chicken Wrap" ClickMode="Release" BorderBrush="#FFF58B09" Name="chkChickenWrap"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkRibeyeSteakWrap" Content="Ribeye Steak Wrap" FontFamily="Lucida Sans" Foreground="Cyan" BorderBrush="Orange"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkShreddedBeefWrap" Foreground="Cyan" FontFamily="Lucida Sans" Content="Shredded Beef Wrap" BorderBrush="Orange"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkCheeseburgerParadiseWrap" Foreground="Cyan" FontFamily="Lucida Sans" BorderBrush="Orange" Content="Cheeseburger Paradise Wrap"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkVeggieWrap" BorderBrush="Orange" Content="Veggie Wrap" Foreground="Cyan" FontFamily="Lucida Sans"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkChiliBurger" Foreground="Cyan" FontFamily="Lucida Sans" Content="Chili Burger" BorderBrush="Orange"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkTiajuanaTorpedo" BorderBrush="Orange" Content="Tiajuana Torpedo" FontFamily="Lucida Sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Stuffed Burger" BorderBrush="Orange" Name="chkStuffedBurger"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkCheeseBurger" BorderBrush="Orange" Content="Cheese Burger" Foreground="Cyan" FontFamily="Lucida Sans"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Patty Melt" BorderBrush="Orange" Name="chkPattyMelt"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Harry's Big Barn Burger" BorderBrush="Orange" Name="chkHarrysBigBarnBurger"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkTheReuban" BorderBrush="Orange" Content="The Reuban" FontFamily="Lucida Sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkBBQBeefSandwich" Foreground="Cyan" FontFamily="Lucida Sans" Content="BBQ Beef Sandwich" BorderBrush="Orange"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkSteakSandwich" BorderBrush="Orange" Content="Steak Sandwich" FontFamily="Lucida Sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkFrenchDip" BorderBrush="Orange" Content="French Dip" FontFamily="Lucid sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Foreground="Cyan" FontFamily="Lucida Sans" Content="Chili Dog" BorderBrush="Orange" Name="chkChiliDog"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkChickenFriedSteakSandwich" BorderBrush="Orange" Content="Chicken Fried Steak Sandwich" FontFamily="Lucida Sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkClubSandwich" BorderBrush="Orange" Content="Club Sandwich" Foreground="Cyan" FontFamily="Lucida Sans"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkCajunCatfishSandwich" Foreground="Cyan" FontFamily="Lucida Sans" Content="Cajun Catfish Sandwich" BorderBrush="Orange"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkEggAndCucumberTeaSandwich" BorderBrush="Orange" Content="Egg &amp; Cucumber Tea Sandwiches" FontFamily="Lucid sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
     <CheckBox Name="chkSmokedSalmonCrosini" BorderBrush="Orange" Content="Smoked Salmon Crosini Recipe" FontFamily="Lucida Sans" Foreground="Cyan"> 
      <CheckBox.Background> 
       <SolidColorBrush /> 
      </CheckBox.Background> 
     </CheckBox> 
    </ListBox> 
</ComboBox>