Click here to Skip to main content
15,902,874 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all
I have a C# WPF listbox. My problem is that the scroll bar is now shown when items get so long.

please have a look at my code:
XML
<ListBox Margin="12,103,0,0" Name="listBoxOutside" ItemsSource="{Binding Path=TagFamilyCollection}">
    <ListBox.Template>
        <ControlTemplate>
            <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" >
                <ItemsPresenter/>
            </Border>
        </ControlTemplate>
    </ListBox.Template>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Margin="2,3,2,1" Background="LightSkyBlue">
                <StackPanel>
                    <TextBlock Text="{Binding Path=Title}" Margin="3"/>
                    <ListBox Name="listBoxInside" ItemsSource="{Binding Path=TagItemCollection}" AllowDrop="True" Drop="listBoxInside_Drop" MouseMove="MouseMoveHandler">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="Black" BorderThickness="1" CornerRadius="2" Margin="2">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Path=Name}" Margin="3" />
                                        <Button Name="buttonRemove" Padding="0" Style="{StaticResource FlatCloseButton}" >
                                            <Image Source="/Resources/close.png" Stretch="UniformToFill" />
                                        </Button>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>



I have used:
C#
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True/False"


still it doesnt work.
If I remove the border, the problem will solve but I want to keep the border as well.
Posted
Updated 13-Apr-17 5:19am

Hi,

Try adding a ScrollViewer inside the Border, something like this:

XML
<ListBox Margin="12,103,0,0" Name="listBoxOutside" ItemsSource="{Binding Path=TagFamilyCollection}">
    <ListBox.Template>
        <ControlTemplate>
            <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" >
                  <scrollviewer cancontentscroll="False"> 
                      <ItemsPresenter/>
                  </scrollviewer>
            </Border>
        </ControlTemplate>
    </ListBox.Template>


Should work now.
 
Share this answer
 
Ca ne marche pas !
scrollviewer n'existe pas !
 
Share this answer
 
Comments
[no name] 13-Apr-17 11:44am    
Seriously? THIS is your only contribution in 8 years?
Kats2512 14-Apr-17 1:42am    
lol don't even understand this answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900