Switching Assets |
The following code can be used to set the AssetInstance of a screen and navigate to that screen. NOTE: this can be accomplished without scripting by using the NavigateSource property to navigate to a a different screen. The asset context of the current control is used when navigating to the screen.
public void OnClick(object sender, EventArgs eventArgs) { // assuming that the sender base control has an "AssetInstance" property PropertyAssetInstance assetInstance = ControlBase.GetProperty<PropertyAssetInstance>(sender, "AssetInstance"); //// in case the asset instance is actually set on a parent control //PropertyAssetInstance assetInstance = GetAssetInstance(sender as ControlBase); if (assetInstance != null) { string screenName = "Screen2"; ControlScreen screen = Application.Screens[screenName] as ControlScreen; screen.AssetInstance = assetInstance; Application.CurrentScreen = screen; } } private PropertyAssetInstance GetAssetInstance(ControlBase control) { if (control == null) return null; if (ControlBase.HasProperty(control, "AssetInstance")) { PropertyAssetInstance assetInstance = ControlBase.GetProperty<PropertyAssetInstance>(control, "AssetInstance"); if (assetInstance != null) return assetInstance; } return GetAssetInstance(control.Parent as ControlBase); }