1

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.
G. Lombard
  • 3,569
  • 1
  • 29
  • 30
  • You should be calculating the `Left` and `Top` values based on the size of the screen rather than hardcoding values which will need changing for different screen resolutions. – ChrisF Feb 01 '11 at 15:49
  • Thanks @ChrisF, I should have mentioned (a) I don't hard code the Top/Left values in my app, I only did it in the code snippet above to illustrate the problem; (b) I would like to detect the screen/desktop size, but couldn't find a way to do it in Silverlight. – G. Lombard Feb 02 '11 at 16:09
  • good point. That's a separate question ;) – ChrisF Feb 02 '11 at 16:11

2 Answers2

1

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.

Aaron McIver
  • 24,527
  • 5
  • 59
  • 88
  • Thanks @Aaron! I should have mentioned that I already have the 'Set window location manually' box checked in the 'Out-of-Browser Settings' dialog. The problem is, while I can successfully set the position of the window manually, it appears that there is a maximum for the 'Top' property (640 in my case). Even setting Top in the Out-Of-Browser Settings doesn't solve the problem. Also, I don't really hard code the Top/Left values in my app, the actual code simply saves the last window position in IsolatedStorage when closing the app, and then I move the window after startup. – G. Lombard Feb 02 '11 at 16:16
  • @codeblast Are you doing something similar to this (scroll to the bottom)? http://msdn.microsoft.com/en-us/library/system.windows.window.top(v=VS.95).aspx in that you save off the top/left/width/height via IsolatedStorage and restore them as such yet it does take effect? Is there a max* on any of your properties within the Window? What resolution are you running? – Aaron McIver Feb 02 '11 at 16:28
  • Hi @Aaron, yes that's exactly what I do! (Save top/left in Application_Exit and load in Application_Startup.) My resolution is 1280x800. This may be relevant but doesn't exactly describe my problem: http://forums.silverlight.net/forums/t/192180.aspx - seems like Silverlight adds some padding to the window when manually setting Top/Left. I may just have to accept that I can't position the window too close to the bottom of the screen. – G. Lombard Feb 03 '11 at 12:18
1

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

JJR89
  • 11
  • 1