如何将 Silverlight OOB 窗口定位到桌面的右下角?

发布于 2024-10-15 10:26:16 字数 1338 浏览 2 评论 0原文

我正在尝试将浏览器外 (OOB) Silverlight 应用程序移至系统托盘上方的右下角。该应用程序的大小为 160x100。

我只是无法将其距离屏幕底部足够近。当我将“Top”属性设置为高于某个值时,它就会被忽略。

例如,在我的 App.xaml.cs 中:

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new MainPage();
    if (App.Current.HasElevatedPermissions &&
        App.Current.IsRunningOutOfBrowser)
    {
        Window w = App.Current.MainWindow;
        w.Width = 160;
        w.Height = 100;
        w.Left = 1108;
        // Up to this point the above all works ok.
        w.Top = 603; // This is ignored if over 602!
    }
}

如果 Window Style='Default' 的值大于 602,或者 Window Style='No Border' 的值大于 640,则忽略设置 App.Current.MainWindow.Top。

如果我将“顶部”值设置为高于 603,它只会默认为“项目设置”中“浏览器外设置”对话框中指定的顶部(在我的例子中为 50)。没有抛出异常。

“Left”属性似乎没有这个问题:我可以设置“Left”以将窗口向右移动到屏幕的右侧。

我使用的是 Windows XP SP3 和 Silverlight 4.0 / VS2010。我已选中“在浏览器外部运行时需要提升信任”框。

为什么我无法在屏幕上进一步向下移动窗口?

有没有其他方法可以使我的窗口看起来“停靠”在屏幕的右下角?

谢谢!

更新: 我应该提到:

  • 我已经选中了“浏览器外设置”对话框中的“手动设置窗口位置”框。在这里设置 Top/Left 属性(与代码中相反),结果是相同的:如果我将“Top”设置为超过 640 的值(窗口样式 =“无边框”),则窗口将放置在中间桌面的位置,而不是指定的坐标。
  • 我并没有真正在我的应用程序中将顶部/左侧设置为硬编码值——我在上面的代码片段中这样做只是为了说明问题。在实际的应用程序中,我让用户移动窗口,然后在应用程序退出时保存位置。
  • 我想检测屏幕/桌面尺寸,但找不到在 Silverlight 中执行此操作的方法。

I'm trying to move an Out-of-browser (OOB) Silverlight app to the bottom right corner, above the systray. The app is sized to 160x100.

I just can't get it close enough to the bottom of the screen. The moment I set the "Top" property above a certain value, it is just ignored.

For example in my App.xaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new MainPage();
    if (App.Current.HasElevatedPermissions &&
        App.Current.IsRunningOutOfBrowser)
    {
        Window w = App.Current.MainWindow;
        w.Width = 160;
        w.Height = 100;
        w.Left = 1108;
        // Up to this point the above all works ok.
        w.Top = 603; // This is ignored if over 602!
    }
}

Setting App.Current.MainWindow.Top is ignored if the value is greater than 602 for Window Style='Default', or greater than 640 for Window Style='No Border'.

If I set the 'Top' value above 603 it just silently defaults to the Top specified in the Out-Of-Browser Settings dialog in the Project settings (50 in my case). No exception is thrown.

The 'Left' property doesn't seem to have this problem: I can set Left to move the window right up the right-hand side of the screen.

I'm using Windows XP SP3 and Silverlight 4.0 / VS2010. I've checked the 'Require elevated trust when running outside the browser' box.

Any reason why I can't move my window further down on the screen?

Is there any other way to make my window appear to be "docked" to the bottom right of the screen?

Thanks!

Update:
I should have mentioned:

  • I have checked the 'Set window location manually' box in the 'Out-of-Browser Settings' dialog. Setting the Top/Left properties here (as opposed to in the code), the result is the same: if I set 'Top' to a value over 640 (window style='No Border') then the window is placed in the middle of the desktop, instead of at the specified coordinates.
  • I don't really set the Top/Left to hardcoded values in my app -- I've done so in the code snippet above just to illustrate the issue. In the actual app, I let the user move the window, then I save the position when the app exits.
  • I would like to detect the screen/desktop size, but couldn't find a way to do it in Silverlight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞳孔里扚悲伤 2024-10-22 10:26:16

您需要设置 WindowStartupLocation 为手动

<OutOfBrowserSettings.WindowSettings>  
    <WindowSettings Title="Silverlight Application"   
                    WindowStartupLocation="Manual"  
                    Left="0"  
                    Top="0"  
                    Width="640"  
                    Height="480"/>  
  </OutOfBrowserSettings.WindowSettings> 

如果需要,您还可以通过隐藏代码访问 OutOfBrowserSettings.WindowSettings

You need to set the WindowStartupLocation to Manual.

<OutOfBrowserSettings.WindowSettings>  
    <WindowSettings Title="Silverlight Application"   
                    WindowStartupLocation="Manual"  
                    Left="0"  
                    Top="0"  
                    Width="640"  
                    Height="480"/>  
  </OutOfBrowserSettings.WindowSettings> 

You can also access the OutOfBrowserSettings.WindowSettings via code behind if needed.

萌能量女王 2024-10-22 10:26:16

试试这个:

    Window w = App.Current.MainWindow;
    w.Width = 1;
    w.Height = 1;
    w.Left = 1108;        
    w.Top = 603; 
    w.Width = 160;
    w.Height = 100;

但使用 try catch

Try this:

    Window w = App.Current.MainWindow;
    w.Width = 1;
    w.Height = 1;
    w.Left = 1108;        
    w.Top = 603; 
    w.Width = 160;
    w.Height = 100;

but use try catch

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文