我的C#WPF列表框有边框时没有滚动条! [英] My C# WPF listbox does't have scrollbar when it has border!

查看:77
本文介绍了我的C#WPF列表框有边框时没有滚动条!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个C#WPF列表框。我的问题是,当项目变得很长时,滚动条现在会显示。



请查看我的代码:

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:

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

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.

推荐答案

您好,



尝试添加边框内的ScrollViewer ,如下所示:



Hi,

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

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


Ca ne marche pas!

scrollviewer n'existe pas!
Ca ne marche pas !
scrollviewer n'existe pas !


这篇关于我的C#WPF列表框有边框时没有滚动条!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆