在我的项目中有许多嵌套的网格.并且大多数行和列宽度在XAML中定义为"*".
我试图通过将其他行的高度设置为0来扩展特定行(比如说Row1),并且我使用.ActualHeight属性来获取Row1的宽度,然后它不给我实际高度.
据我所知,这是因为网格行和列的高度和宽度是在渲染时设置的.
我在网上搜索,有人建议使用UpdateLayout()方法..但这也不适合我.
我无法发布代码片段,因为它是非常长的代码.
我在c#.net wpf中的项目.
您需要进行完整的布局更新,即需要调用Measure,Arrange和UpdateLayout:
//Make the framework (re)calculate the size of the element
_Element.Measure(new Size(Double.MaxValue, Double.MaxValue));
Size visualSize = _Element.DesiredSize;
_Element.Arrange(new Rect(new Point(0, 0), visualSize));
_Element.UpdateLayout();
Run Code Online (Sandbox Code Playgroud)
_Element是一个FrameworkElement(Grid是一个).
归档时间: |
|
查看次数: |
2786 次 |
最近记录: |