c# - 列表框延伸到页面之外

标签 c# .net silverlight xaml listbox

我在 silverlight 应用程序的边框内的堆栈面板内有一个列表框,当我向列表框中添加任何内容时,它的高度就会增加,因此滚动条永远不会被使用,并且它会延伸到边框元素的边界之外。我已经尝试显式设置列表框、边框和堆栈面板的高度属性,但它仍然超出了这个范围。

这是我的代码:

<Border x:Name="articlePane">
                <StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top">
                        <Button Content="Latest" MouseEnter="HandleRollInAnimation" MouseLeave="HandleRollOutAnimation" />
                        <Button Content="Pending" MouseEnter="HandleRollInAnimation" MouseLeave="HandleRollOutAnimation" />
                        <Button Content="Done" MouseEnter="HandleRollInAnimation" MouseLeave="HandleRollOutAnimation" />
                    </StackPanel>
                    <ListBox x:Name="articleList" Margin="5" Background="Transparent" ItemsSource="{Binding}" 
                             ScrollViewer.VerticalScrollBarVisibility="Visible">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Center">
                                    <Image x:Name="articleImage" />
                                    <TextBlock x:Name="articleTitle" Text="{Binding Path=Title}" FontSize="18" FontWeight="Bold"
                                               Margin="5"/>
                                    <TextBlock x:Name="articleDate" Text="{Binding Path=Date}" FontSize="14" Foreground="Gray"
                                               Margin="5"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>
            </Border>

最佳答案

我有一种感觉,StackPanel 会永远增加高度。我认为在这种情况下,您最好在边框内使用网格布局。将 Button StackPanel 放在一个高度定义的行中,将 ListBox 放在一个自动调整大小 * 高度的行中。这样网格就会固定在表单的范围内。

关于c# - 列表框延伸到页面之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4316471/

相关文章:

c# - Win 10 通用窗口应用程序上的 ContentDialog.showAsync

c# - 使用 Oracle.DataAccess.Client;下载并安装 OPD.NET 后未找到

c# - ASP.NET - 动态更改样式表

c# - 使用 html 编码或转义字符加载 XML 或 XHTML 内容

c# - 在 C# .NET 2.0 或更高版本中,如何获取 Vista PC 上所有已安装应用程序的列表

silverlight - 使用 WCF RIA Services SP1 如何通过 Entity Framework 复杂类型使用存储过程?

c# - 将数据从 Silverlight 传递到 ASP.NET 页面

silverlight - 遍历Silverlight中的枚举?

c# - 如何在 ASP.NET 中上传图像文件而不进行任何回发

.NET:未设置必需属性时抛出哪个异常?