积极答复者
ActualHeight和ActualWidth的获取,老问题

问题
-
在MainWindow.xaml中已经定义了Grid:grFrame
嵌入层级:
<MainWindow> <grWindow> <grFrame/> </grWindow> </MainWindow>
Grid均没有设定固定尺寸,占用整个窗口
//MainWindow.xaml.cs public MainWindow() { InitializeComponent(); } private void bt_Click(object sender, RoutedEventArgs e) { controler.Start(grFrame); //... } //...
//Controler.cs public void Start(Panel showPanel) { //在此处已定义Canvas类型的Camera //在此处,grFrame以参数形式转化为了showPanel showPanel.Children.Add(Camera); Camera.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); //在此处如何获得正确的Camera的ActualWidth? } //...
因为在将Camera添加到grFrame之后,会立即有其他的方法调用会引用到Camera.ActualWidth,所以希望能够立即正确表示。
如代码所示,使用Camera.Measure()完全没有用,我是否用错了?
答案
-
你好,
你这边应该是用错了。我们要获取Canvas的ActualWidth属性必须要Canvas已经在页面上渲染了。否则我们获得的值应该是0.0.
谢谢!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Lymim 2014年3月15日 7:37
全部回复
-
你好,
你这边应该是用错了。我们要获取Canvas的ActualWidth属性必须要Canvas已经在页面上渲染了。否则我们获得的值应该是0.0.
谢谢!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Lymim 2014年3月15日 7:37