I have the following code in a click handler of a Silverlight application (4). I have two problems getting this to work.
1) While the browser doesn't have pop-ups disable IsPopupWindowAllowed is returning false. Why?
2) If I ignore the if test, the window doesn't show. :(
if ( HtmlPage.IsPopupWindowAllowed )
{
var options = new HtmlPopupWindowOptions
{
Left = 0,
Top = 0,
Width = 500,
Height = 400,
Scrollbars = false,
Status = false
};
HtmlPage.PopupWindow(new Uri("http://www.monster.com"), "_blank", options);
}
Make sure all the following is done correctly, as mentioned on this page, http://msdn.microsoft.com/en-us/library/system.windows.browser.htmlpage.popupwindow%28v=vs.95%29.aspx
The AllowHtmlPopupWindow property must be set to true on the Silverlight plug-in.
The call to PopupWindow must be triggered by a user-initiated click on a visible area of the hosting Silverlight plug-in. PopupWindow can be called only once per interactive user event.
This prevents the display of multiple pop-ups during the course of a single click on the Silverlight plug-in.
Related
We have an app that shows a splash screen which shows some data so we have a custom splash screen. Also because of historic reasons all app initialization happens on the UI thread, so my solution for that was to show the splash screen in a separate STA thread.
private void ShowSplashScreen()
{
var mainDispatcher = Dispatcher.CurrentDispatcher;
var splashScreenThread = new Thread(() =>
{
new SplashScreen().Show();
_splashScreenThreadDispatcher = Dispatcher.CurrentDispatcher;
Dispatcher.Run();
});
splashScreenThread.SetApartmentState(ApartmentState.STA);
splashScreenThread.Start();
}
private void CloseSplashScreen()
{
_splashScreenThreadDispatcher.InvokeShutdown();
}
And then when initialization is done this runs
var mw = new MainWindow();
Application.Current.MainWindow = mw;
mw.Show();
CloseSplashScreen();
mw.Activate();
This works fine in normal desktop mode => the main window shows, the splash screen closes and the main window is visible.
However when I switch windows to tablet mode and launch the app from the start screen, when the main window shows it only flashes and goes to background again and it shows the start screen.
If I don't close the splash then all is still visible, but that's not an option of course.
I tried various things already with topmost, different orders of calling me.Show(), mw.Activate(), me.Focus(), setting focus in Closing handler of splash screen, but nothing seems to work.
Any ideas on how this can be fixed? In production the app is only used on tablets so it's a must have for us.
Regards
Stan
I fixed it by using a popup instead of a window for the splash screen. A popup does not require an owner or parent so it's possible to use it, and when the popup is closed the start screen doesn't go in front of the main window.
I have a silverlight application, with a control (kind of tooltip) inside a popup, and want to remove this popup in certain case.
In silverlight spy I see that this popup is not a child element of the rootvisual, but appears at the same level.
How can I remove this Popup?
Thanks
OK, So I managed to solve this issue, and it was fairly easy at last.
This is the code I used:
var popups = VisualTreeHelper.GetOpenPopups();
foreach (Popup pop in popups)
{
if (pop != null && pop.Child is ToolTip)
{
((ToolTip)pop.Child).IsOpen = false;
}
}
I have a section with silverlight component that is visible depending on the status of records.
If I set that section's Visible By Default = true and hide it in some cases => it works.
But I could not set it Visible by default = true because the screen loading is NOT smooth (the silverlight component appears and disapears)
Alternately, I hide it by default (Visible by default = false) and only show it if needed (jscript - onload)
=> it does NOT work!! The silverlight component is empty! I've already tried a very simple silverlight component with just a simple label, but it's still the same issue.
I guess it's a problem of loading siverlight webresource on MSCRM 2011...
Please help. Thanks.
I found out the problem, I think it's a bug in CRM. In my onload, I add it
var s = document.getElementById("WebResource_silverlight");
s.style.height = "100%"
and then it's visible again :)
I want to get screenshot of screen under my form, so I hide it first and show after capturing. But on my Windows 7 form is not completely minimize, so I get form on screenshot. How can I be sure that my form is competely minimize?
WindowState = FormWindowState.Minimized;
Bitmap screenshot = ScreenUtils.ScreenShot();
background = screenshot;
WindowState = FormWindowState.Normal;
P.S. Hide() and Show() have the same problem.
you could set your forms opacity to 0, call refresh to make sure the painting is done, capture, reset opacity to 1 and call refresh again
Did you try to build in a sleep before making a screenshot?
RTM version of the developer tools.
I am building an app. In parts of the app I have some text provided by a web service, I take this text and process it to make the URLs in the text act as hyperlinks.
The container for this is a wrap panel.
<wrap:WrapPanel x:Name="PostMessage2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
Then in the constructor of the page I have this simple code.
PostMessage2.Children.Add(new HyperlinkButton()
{
Content = new TextBlock()
{
Text = "test url",
Foreground = new SolidColorBrush(Colors.White)
},
NavigateUri = new Uri("http://www.google.com/")
});
(I know this code is will not open an IE session and navigate to the Url)
Now when I run this program, I will not see anything visible on the screen, but if I tap the screen where the start of the url should be, then it will try to navigate to the url (which causes an exception as the navigation isn't handled correctly).
If I add a Textblock before and after the URL the test in those blocks is visible, and they will be separated by approximately 3 spaces, which if you tap the middle of this it will try to navigate to the url.
So my question is why are the hyper-links not visible but they are active as you can tap them, am I missing some obvious property or setting?
Thanks in advance for help.
You don't need to set the Content of the HyperlinkButton to be a TextBlock. It's expecting a string and you can set the Foreground color on the HLB:
PostMessage2.Children.Add(new HyperlinkButton()
{
Content = "test url",
Foreground = new SolidColorBrush(Colors.White),
NavigateUri = new Uri("http://www.google.com/")
});