C# 如何使组合框中的列表框在WPF中垂直滚动

C# 如何使组合框中的列表框在WPF中垂直滚动,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,请大师们,我在我的wpf应用程序中有组合框,并且能够在其中添加包含复选框的列表框,以便用户可以从一个类别中选择多个项目。但我现在面临的问题是: **列表框无法显示整个复选框,因为尽管将高度设置为“自动”,但它们拒绝滚动 提前感谢您花时间考虑这个问题 *以下样式适用于其中一个梳妆盒,因为s相同步骤适用于其余的* 使用Scrollviewer 将所有可滚动控件放在scrollviewer中。为了垂直滚动列表框项目,您可能需要为项目面板指定最大高度 这段代码将完全满足您的要求: <ComboB

请大师们,我在我的wpf应用程序中有组合框,并且能够在其中添加包含复选框的列表框,以便用户可以从一个类别中选择多个项目。但我现在面临的问题是:

**列表框无法显示整个复选框,因为尽管将高度设置为“自动”,但它们拒绝滚动

提前感谢您花时间考虑这个问题

*以下样式适用于其中一个梳妆盒,因为s相同步骤适用于其余的*


使用Scrollviewer


将所有可滚动控件放在scrollviewer中。

为了垂直滚动列表框项目,您可能需要为项目面板指定最大高度

这段代码将完全满足您的要求:

<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>

<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>