I have the following simple program that switches the context of a frame back and forth between two different pages. The first page is just a picture and loads fine, but the second page is a frame that’s source is set to live weather radar.
http://www.wunderground.com/auto/wxmap/IN/Carmel.html. When the timer switches the context of my frame to the weather radar page, it only then begins it’s load and spends the first 3-4 seconds loading the page. I checked the .Navigated Event of the frame at it fires pretty much right after I create the page and assign it to _nextslide, so why is my frame waiting til the page is shown to render the website? It would be perfect if I could show the site fully loaded.
XAML:
<Page>
<Viewbox Stretch="Fill" Margin="15">
<Frame Height="800" Width="1280" Content="{Binding SlideFrame}"/>
</Viewbox>
</Page>
C#:
private Page _slideFrame;
private Page _nextFrame;
private DispatcherTimer _slideChangeTimer;
private int currentSlide = 1;
// Property
public Page SlideFrame
{
get { return _slideFrame; }
set
{
_slideFrame = value;
NotifyPropertyChanged("SlideFrame");
}
}
// ViewModel Constructor
public Page1ViewModel()
{
this.SlideFrame = new Slide1();
_nextFrame = new Slide2();
_slideChangeTimer = new DispatcherTimer();
_slideChangeTimer.Interval = TimeSpan.FromSeconds(8);
_slideChangeTimer.Tick += new EventHandler(SlideChange_Tick);
_slideChangeTimer.Start();
}
// 8 second timer event handler
private void SlideChange_Tick(object sender, EventArgs e)
{
if (currentSlide == 1)
{
this.SlideFrame = _nextFrame;
_nextFrame = new Slide1(false);
currentSlide = 2;
}
else
{
this.SlideFrame = _nextFrame;
_nextFrame = new Slide2();
currentSlide = 1;
}
}
Does not use frame or web pages but it shows how to fetch data in the background to not block the UI in a timer. You should add logic to wait if the last web page was not yet fetched.