简体   繁体   中英

How do i resize a silverlight app based on its contents?

I have a simple app that I'd like to change the size of when I load the contents.

For example, let's say I load an image of size 100.

How do I change the size of the container in which the silverlight is being rendered?

Solution--

Rather than going through the page, you need to go through the browser object.

Here's the solution I found:

width = 200;
height = 200;

var host = HtmlPage.Document.HtmlPage.Plugin.Id);
host.SetStyleAttribute("width", width.ToString());
host.SetStyleAttribute("height", height.ToString());

The once the container is resized you can get notified:

    public Page()
    {
        InitializeComponent();

        App.Current.Host.Content.Resized += (s, e) =>
        {

            // Place here your layour resize code...
            this.Width = App.Current.Host.Content.ActualWidth;
            this.Height = App.Current.Host.Content.ActualHeight;

        };

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM