如何获得视图框的宽度和高度 [英] How do I get the width and height of my viewbox
问题描述
大家好,
我需要获得我的Viewbox的动态高度和宽度
我的xaml的层次结构是这样的:
Hello everyone,
I need to get the dynamical Height and Width of my Viewbox
The hierarchy of my xaml is like this:
<Grid>
<DockPanel>
<Border>
<ViewBox/>
</border>
</DockPanel>
</Grid>
视图框宽度为自动,高度绑定到我的控制器中的变量。
类层次结构如下:
Xaml< - - >控制器
(xaml.cs大多被忽略)
现在我的问题是即使在直接代码隐藏(xaml.cs) ),我得到0作为ActualWidth和ActualHeight。所以如果我改变主窗口的尺寸,我甚至不会得到标准的宽度和高度,更不用说动态了。
如果Code-Snippets或信息是失踪。请告诉我。
问候
Richard
什么我试过了:
我试图在代码背后获得尺寸:
高度/宽度(仅限得到标准高度和NaN宽度)
ActualHeight / ActualWidth(均为0)
RenderSize.Height / RenderSize.Width(均为0)
The Viewbox Width is on "Auto" and the Height is binded to a variable in my Controller.
The Class hierarchy is like this:
Xaml <--> Controller
(the xaml.cs is mostly ignored)
Now my problem is that even in the direct code-behind (xaml.cs), I get 0 as ActualWidth and ActualHeight. So I don't even get the standart Width and Height not to mention the dynamical one if I change the dimension of my mainwindow.
If Code-Snippets or information are missing. Please tell me.
Regards
Richard
What I have tried:
I tried to get the Dimensions with in the Code-Behind:
Height/Width (Only get the standard Height and NaN for Width)
ActualHeight/ActualWidth (both are 0)
RenderSize.Height/RenderSize.Width (both are 0)
推荐答案
解决方案很简单。在得到宽度和高度之前,我没有渲染图像。
The solution was simply. I didn't render the image before i get the Width and Height.
这篇关于如何获得视图框的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!