1

I need to get the dynamic Height and Width of my Viewbox The hierarchy of my xaml is like this:

<Grid>
 <DockPanel>
  <Border>
   <ViewBox/>
  </border>
 </DockPanel>
</Grid>

The Viewbox Width is on "Auto" and the Height is bound 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. If I change the dimension of my mainwindow I don't even get the standard Width and Height not to mention the dynamic one.

If Code-Snippets or information are missing, please tell me.

Here is the image with the red border. You have to look closey at the bottom (a small red Border): enter image description here

Regards Richard

What I have tried:

I tried to get the Dimensions within 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)

I also tried the solution in this post: Getting current size of WPF controls It was the reason why I used the RenderSize solution

Community
  • 1
  • 1
Evosoul
  • 197
  • 1
  • 12
  • When are you trying to get the Actual/Render sizes ? – Panda Jun 14 '16 at 13:54
  • roundabout once per second. – Evosoul Jun 14 '16 at 13:57
  • It probably is Because you are getting Actual/Render sizes before the window gets rendered. Did you try capturing these values after checking if the rendering is done? – Kamil Solecki Jun 14 '16 at 14:01
  • @KamilSolecki Yes, Inside of the window there is a webcam stream which is Visisble. When it says that the Height and Width is the same (in this case the binding value of the Height which is 877). Which gives the standard dimension. But if I change the Dimensions of my MainWindow, as example to 200x200 than it still says that the Viewbox dimension is 877 – Evosoul Jun 14 '16 at 14:05
  • Why do you need size of `ViewBox`? To do what? The `Content` of it will be resized disregards of `ViewBox` size according to `ViewBox.Stretch` rule. Another thing, I suspect problem with layout, can you make a screenshot of this window where you set `Border.Backround` to something like `Red`. It could be 0-size for real. – Sinatr Jun 14 '16 at 14:31
  • @Sinatr I need the resolution for a zoom factor. My camera caputres images with the resolution 3000x3000 and it stretches to the resolution of the ViewBox. But I need to see the Image with different zoom factors. – Evosoul Jun 14 '16 at 14:43
  • You want to know [zoom factor](http://stackoverflow.com/q/5423334/1997232) of content. It has nothing to do with `ViewBox` size (in fact you don't care, you only care how picture is reduced inside `ViewBox`). Or do you want something else? – Sinatr Jun 14 '16 at 14:47
  • @Sinatr Yes I want something else, We already have a zoom factor. It works but the zoom factor isn't correct. The 1x zoom is when the image is stretched inside the Viewbox. But that isn't correct. I have to recalculate it refering to the Viewbox Width/Height and the desktop resolution – Evosoul Jun 15 '16 at 05:58

1 Answers1

0

I end this question because the mainquestion was answered. It was answered in the comments from Kamil Solecki

Evosoul
  • 197
  • 1
  • 12