[英]How to set minimum width and height in a silverlight OOB application?
I am trying to set a minimum width and height for my silverlight 4 OOB application without any success so far. 我试图为我的silverlight 4 OOB应用程序设置最小宽度和高度,但到目前为止没有任何成功。 Can someone help me as i keep getting this error messages:
当我不断收到此错误消息时,有人可以帮我吗:
"An object reference is required for the non-static field,method, or property 'kat.MainPage.Width.get' and 'kat.MainPage.Height.get'
“非静态字段,方法或属性'kat.MainPage.Width.get'和'kat.MainPage.Height.get'需要对象引用。
My code is the following: 我的代码如下:
namespace kat
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.SizeChanged +=new System.Windows.SizeChangedEventHandler(LayoutRoot_SizeChanged);
}
public double Width { get; set; }
public double Height { get; set; }
private void LayoutRoot_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
if (kat.MainPage.Width <500)
kat.MainPage.Width =500;
if (kat.MainPage.Height <500)
kat.MainPage.Height =500;
}
}
}
I assume kat is just your namespace... 我认为Kat只是您的命名空间...
You are basically trying to access members of an object without actually using a pointer to the object. 您基本上是在尝试访问对象的成员,而不实际使用指向该对象的指针。
kat.MainPage
is a class, not an object so any references to kat.MainPage.anything
will fail with that error. kat.MainPage
是一个类,而不是对象,因此对kat.MainPage.anything
任何引用kat.MainPage.anything
将因该错误而失败。
You just wanted: 您只想要:
private void LayoutRoot_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
if (Application.MainWindow.Width < 500)
Application.MainWindow.Width = 500;
if (Application.MainWindow.Height < 500)
Application.MainWindow.Height = 500;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.