-1

I am trying to develop a program that has the possibility to adapt at the screen resolution of the user.

I am using mvvm with the pushbinding of Meleak to obtain the actual size of my MainWindow:

Getting Window Properties in ViewModel

For positioning my object, I am using GridRow and GridColumn. Now I am trying to optimize this size, for that I have the need to get the ActualSize of my other UIElment, but like their size depend of their contents, I don't know how I can get their size, I try with a binding onewaytosource but I obtain a size of 0.0 and obviously is not the size after initialisation.

Community
  • 1
  • 1
Gat
  • 115
  • 3
  • 11
  • I have edited your question to what I think you were trying to say, I think you will need to add more details though. – Gaz Winter Jun 19 '12 at 10:26
  • Yes i post this question a bit too fast, sorry for that. – Gat Jun 19 '12 at 10:30
  • 1
    @Gat: You have any sample code for what you're trying to do? – Fredrik Hedblad Jun 19 '12 at 10:33
  • @Meleak : I make you a quick sample – Gat Jun 19 '12 at 11:59
  • @Meleak : you can find an example here : https://docs.google.com/file/d/0B5Iv6R2fQq3UV1JJZ09iNlBNTm8/edit?pli=1 – Gat Jun 19 '12 at 13:39
  • @Meleak just remove .doc, else in this example is a border(in my project it is datagrid) that has this size depend of listbox, but if you resize the mywindow,you can see it has inifiny size. – Gat Jun 19 '12 at 13:41

1 Answers1

0

The event Loaded can be used to measure the ActualHeight of a visual object.

If this is used on the window as below, the internal content should all be rendered and be available for you to reference.

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var temp = this.ActualHeight;
}

In this example I am finding the window's ActualHeight but you can use it for any object within the window.

If you have nested windows/views the Loaded event is available on them as well.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
klaverty
  • 108
  • 1
  • 5