Returning all NavigationViewModel screens?
-
Wednesday, March 21, 2012 2:58 PM
I am trying to gain access to all screens in a LightSwitch app via my custom shell's code (as opposed to binding a control through XAML).The LS App I am testing with has 9 screens but my code is only returning 5. It looks like the IServiceProxy is only returning screens where isEnabled is true.
// Prime the ViewModel
this.ServiceProxy.NavigationViewModel.NavigationItems.Count();
foreach (INavigationItem navGroup in VsExportProviderService.GetExportedValue<IServiceProxy>().NavigationViewModel.NavigationItems)
{
// Cast the current navGroup into an actual INavigationGroup
INavigationGroup objNavGroup = (INavigationGroup)navGroup;
foreach (var screen in objNavGroup.Children)
{
// There are only 5 screens available here. There should be more
}
}
Can anybody help please?
Paul.
Website design for £249, Unlimited pages, Facebook and Twitter integration. www.domainscanners.com
All Replies
-
Wednesday, March 21, 2012 3:32 PM
Ran into this as well...
There's some weird stuff going on ( = I don't know what), but when you call that code too early you'll get incorrect results. The reason that you don't run into this issue if you bind controls is that the INavigationGroup extends INotifyPropertyChanged, thus the bindings correctly update as the INavigationGroup implementations are loading...
=> so hook up to the PropertyChanged event, and do a new execution of your code each time it fires.
Let us know if that solves anything!
Lightswitch blog: http://janvanderhaegen.wordpress.com || About me: http://about.me/jan.van.der.haegen || "The improbable we do, the impossible just takes a little longer." (Steven Parker)
- Marked As Answer by Hale Wednesday, March 21, 2012 3:54 PM
-
Wednesday, March 21, 2012 3:54 PM
Thanks Jan - Strange one that but problem solved thanks to you!
For anyone else with the same issue hook up the property changed event after your default screen loads.
Paul.
Website design for £249, Unlimited pages, Facebook and Twitter integration. www.domainscanners.com
- Edited by Hale Wednesday, March 21, 2012 4:14 PM

