Did you know - Setting Source property through code in Silverlight

by rahul 6/26/2010 5:14:00 PM

In a Silverlight application, create a button and drop a Frame control. If you set the Source property of this Frame control to another page (let's say "/anotherpage.xaml") in design time it will work just fine when you execute this application. But if you want to navigate to a different page using code you may write a code that looks like this…

private void btnNavigate_Click(object sender, RoutedEventArgs e){    
frame1.Source = (new Uri("/anotherpage.xaml");
}

If you execute your application it will error out, saying…

Invalid URI: The format of the URI could not be determined.

To get rid of this problem, use the following code…

private void btnNavigate_Click(object sender, RoutedEventArgs e){
frame1.Source = (new Uri("/anotherpage.xaml", UriKind.Relative));
}

Cheers, Wave
Rahul


Quote of the day:
Adventure is just bad planning. - Roald Amundsen


blog comments powered by Disqus

Rahul Soni

Rahul Soni  Twitter

 LinkedIn

 Facebook

 Email me



Vivek Kumbhar

Vivek Kumbhar  Twitter

 LinkedIn

 Facebook

 Email me


Stack Exchange

profile for Vivek at Server Fault, Q&A for system administrators and IT professionals

profile for Rahul Soni at Stack Overflow, Q&A for professional and enthusiast programmers

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

All Items
Sign in

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Rahul Soni

Powered by BlogEngine.NET 1.4.5.0