tags:

views:

83

answers:

2

I'm currently using a datagrid within a user control. The datagrid resizes based on the number of rows, and therefore goes off the webpage.

I've tried wrapping the control around a ScrollViewer, but in order to have the scroll bar visible and working, I need to set the MaxHeight of the datagrid.

The problem is that I don't know what the MaxHeight of the datagrid should be because it differs based on the size of the browser window appearing on the screen.

Any suggestions on how to determine the correct size of the control?

+1  A: 

In SL4, there is the ViewBox-Control. With its Width and Height set to "Auto", the containing Control (which can be a Container) is stretched to the Size of the Browser-Window.

gammelgul
+2  A: 

Well, I found two ways of doing this.

  • You can set the row height of the grid row, in which the datagrid is, to "*". This should keep all the controls inside of it at a max height of the current browser size.
  • There is a way of manually controlling the height whenever the browser is resized.

public MainPage()

    {

        InitializeComponent();

        App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
    }

    void Content_Resized(object sender, EventArgs e)
    {
        double height = App.Current.Host.Content.ActualHeight;
        double width = App.Current.Host.Content.ActualWidth;

        Test.MaxHeight = height;
    }

Now in this example I simply set the MaxHeight to the height of the browser, however, you can add some logic into calculating the height

Johannes
Option 1 good, seriously if you need option 2 you're doing something wrong.
AnthonyWJones