为什么 DataGrid 是“自动”的宽度突然这么大?
我一直在开发一个带有 wpf 工具包中的数据网格的应用程序,并且 xaml 中未指定宽度(默认为自动),并且它工作正常。当我调整窗口大小时,它会扩展窗口宽度。然而,突然间“自动”宽度很大,我不知道为什么。当我在混合中拉出 xaml 文件时,它显示自动宽度为 50002 像素。自从它发生以来,我几乎没有碰过我的 xaml 中的任何其他内容。有人知道为什么要这样做以及这个数字来自哪里吗?谢谢
I have been working on an app with a datagrid from the wpf toolkit and the width was not specified in the xaml (default to auto), and it was working fine. It would extend the window width as I resized the window. However, all the sudden the "auto" width is massive and I don't know why. When I pull the xaml file up in blend it shows auto width is 50002 pixels. I barely touched anything else in my xaml since it happened. Anyone know why it is doing this and where that number came from? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我见过的最常见的原因是控件位于 Orientation=Horizontal 的 StackPanel 内。 StackPanel 不会在堆叠方向上限制其控件,因此如果没有其他限制,控件会增长到某个最大尺寸。
如果这是问题,请尝试用等效的 DockPanel 或 Grid 替换您的 StackPanel。
The most common cause for this that I've seen is when the control is inside a StackPanel with Orientation=Horizontal. StackPanels don't constrain their controls in the stacking direction so if nothing else constrains the control it grows to some maximum size.
If this is the issue try replacing your StackPanel with an equivalent DockPanel or Grid.
如果您使用 Visual Studio IDE 进行任何手动调整大小,则可能会发生这种情况,或者您可能意外地输入了错误的大小 50002。删除宽度并设置为自动应该可以解决该问题。
If you were doing any manual resizing using the Visual Studio IDE then perhaps this could have happened or you could have accidently typed in the wrong size of 50002. Removing the widths and setting to auto should fix the issue.