简体   繁体   English

如何根据其内容调整Silverlight应用程序的大小?

[英]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. 例如,假设我加载了大小为100的图像。

How do I change the size of the container in which the silverlight is being rendered? 如何更改用于渲染Silverlight的容器的大小?

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;

        };

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Silverlight应用程序内重定向包含Silverlight应用程序的asp.net页面? - How do I redirect the asp.net page that contains a silverlight app from within the silverlight app? 如何自动调整图像大小以适合Silverlight网格单元中已调整大小的画布 - How do I automatically resize an image to fit a resized canvas in a silverlight grid cell 如何将Silverlight应用程序连接到WCF服务? - How do I connect my Silverlight app to a WCF Service? 如何根据窗口的大小调整元素的大小 - How do I resize elements based on the size of the window 我如何让ItemsControl适合其内容并且不考虑其同级元素而垂直扩展? - How do I have an ItemsControl fit its contents and not expand vertically without regard to its sibling elements? 如何根据其内容而不是宽度等属性触发 WPF 网格上的 ValidationRule? - How can I trigger a ValidationRule on a WPF grid based upon its contents, rather than its properties like width? 如何根据列表的子对象属性对列表进行排序? - How do I sort a list based on its child object attributes? 垂直调整StackPanel的大小以适合其内容 - Vertically resize StackPanel to fit around its contents 如何阅读目录及其内容 - How can I read Directory and its contents 如何根据其属性值删除 XML 元素 - How do I remove an XML element based on the value of its attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM