This is a migrated thread and some comments may be shown as answers.

RadModalWindow.WindowOpened event not working correctly with WebBrowser control in it?

1 Answer 74 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
runtastic
Top achievements
Rank 1
runtastic asked on 25 Feb 2011, 11:45 AM
Is it possible that RadModalWindow.WindowOpended event is fired to early?

Basically what I'm trying to do is navigate to an URL every time the window is opened. So I used WindowOpended event to do that. But I'm getting an exception: "You cannot call WebBrowser methods until it is in the visual tree."

Take a look at the following code:

RadModalWindow window;
WebBrowser browser;
private void button_Click(object sender, RoutedEventArgs e)
{
    if (window == null)
    {
        window = new RadModalWindow();
        browser = new WebBrowser();
        window.Content = browser;
        window.WindowOpened += new EventHandler<EventArgs>(window_WindowOpened);
    }
    window.IsOpen = true;
}
 
void window_WindowOpened(object sender, EventArgs e)
{
    // always navigate to the same url when opening the window
    browser.Navigate(new Uri("http://www.google.com"));
}

Currently I have a workaround using a Timer that will fire after 250 ms and then call browser.Navigate(). That works fine. But it would be great if this will work without a timer.

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 01 Mar 2011, 02:51 PM
Hello Buju,

 Thank you for writing.

We will consider the behavior of the WindowOpened event. In the mean time, you can use Dispatcher.BeginInvoke() instead of the timer. For example:

browser.Dispatcher.BeginInvoke(() => browser.Navigate(new Uri("http://www.google.com")));

Please write again if you have other questions or issue you would like to report. 

All the best,
Victor
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Window
Asked by
runtastic
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or