简体   繁体   English

设置'Horizo​​ntalAlignment =“ Stretch”'时,如何获取'Width'?

[英]How to get the 'Width', when set 'HorizontalAlignment = “Stretch”'?

I had booked a Grid with HorizontalAlignment = "Stretch" 我已经预订了一个带有HorizontalAlignment = "Stretch"Grid

And now, I want to know what is its Width ? 现在,我想知道它的Width多少?

I want to do this by C # at runtime. 我想在运行时用C#做到这一点。

Thanks in advance. 提前致谢。

Let's say that you have the following grid: 假设您具有以下网格:

<Grid Name="gvDummyContent" HorizontalAlignment="Stretch" />

An you want to get the height and width of it. 您想要获取它的高度和宽度。 You can do it like this: 您可以这样做:

double actualWidth = gvDummyContent.ActualWidth;
double actualHeight = gvDummyContent.ActualHeight;

Be sure that you are calling these properties after the controls are loaded. 确保在加载控件后调用这些属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 Horizo​​ntalAlignment 和 Horizo​​ntalContentAlignment 不起作用时,如何使 WPF 中的控件拉伸以填充可用宽度? - How can I make controls in WPF stretch to fill available width when HorizontalAlignment and HorizontalContentAlignment don't work? wpf 水平对齐左和拉伸? - wpf horizontalalignment left and stretch? 如何将不同的Horizo​​ntalAlignment设置为ListBoxItems - How to set different HorizontalAlignment to ListBoxItems HorizontalAlignment="Stretch" 在 TreeViewItem 中不起作用 - HorizontalAlignment="Stretch" not working in TreeViewItem 如何在后面的代码中设置TabControl的Horizo​​ntalAlignment - How to set HorizontalAlignment of TabControl in code behind 如何使 DataGrid 列水平对齐拉伸和自定义列名称 - UWP DataGrid - How to make DataGrid columns horizontalalignment stretch & customize column name - UWP DataGrid UWP ItemsStackPanel在ListView内拉伸Horizo​​ntalAlignment - UWP ItemsStackPanel stretch HorizontalAlignment inside a ListView 如何获得ListBox ItemTemplate以在Windows 10通用版本中水平拉伸ListBox的整个宽度? - How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox in Windows 10 universal? 如何使LVI延伸到其容器的宽度? - How to make LVI stretch to width of its container? 设置通用自定义按钮的Stretch / Height / Width属性 - Set stretch/height/width property for a generic custom button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM