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.
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.
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
精彩评论