[英]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.