开发者

How to resize a silverlight control to a full webpage

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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜