简体   繁体   English

如何在Silverlight OOB应用程序中设置最小宽度和高度?

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

相关问题 从Silverlight OOB应用程序如何检查进程是否正在运行 - From Silverlight OOB application how to check if a process is running 如何在Silverlight 5 OOB应用程序中呈现PDF字节数组? - How do I render PDF byte array in Silverlight 5 OOB Application? silverlight 4 OOB 应用程序在部署后无法工作 - silverlight 4 OOB application wont work after deployment 卸载SilverLight OOB应用程序时如何运行某些代码? - How can I run some code when a SilverLight OOB Application is uninstalled? 如何从Silverlight OOB弹出Web浏览器? - How to pop a web browser from Silverlight OOB? 如何检查Silverlight OOB中的互联网连接是否可用 - How to check if internet connection is available in Silverlight OOB 如何使我的 MAUI 应用程序的 window 固定,因此无法调整大小或设置最小高度/宽度? - How can I make the window of my MAUI app fixed, so not resizable or set a minimum height/width? 如何为Windows 8.1应用程序设置最小高度? - How to set minimum height for a Windows 8.1 app? 如何在Silverlight 4中设置数据网格的高度 - How to set the height of a Data Grid in Silverlight 4 将Windows的最小高度和最小宽度绑定到页面 - Bind a windows minimum Height and minimum Width to pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM