public WatAppBar(WatSchema watConfig, CommandBar bottomAppBar, WebView mainWebView) { _watConfig = watConfig; _mainWebView = mainWebView; // Add to current CommandBar in BottomAppBar Wat AppBarButtons if NavBar or AppBar is enabled if ((_watConfig.NavBar == null) && (_watConfig.AppBar == null)) { return; } // Set the page's ApplicationBar var ApplicationBar = bottomAppBar; if (_watConfig.AppBar != null && _watConfig.AppBar.Buttons != null && _watConfig.AppBar.Buttons.Count <= 4) { // IconEnumHelper points to the appropriate files for enum-based IconEnumHelper iconEnums = new IconEnumHelper(); foreach (BarButton bb in _watConfig.AppBar.Buttons) { AppBarButton appBarButton = new AppBarButton(); if (!String.IsNullOrEmpty(bb.Icon) && iconEnums.IsIconAvailable(bb.Icon)) { appBarButton.Icon = new BitmapIcon() { UriSource = iconEnums.GetIconUri(bb.Icon) }; } else { appBarButton.Icon = new BitmapIcon() { UriSource = bb.IconUri }; } appBarButton.Label = bb.Label; appBarButton.Click += appBarButton_Click; ApplicationBar.PrimaryCommands.Add(appBarButton); } } if (_watConfig.NavBar != null && _watConfig.NavBar.Buttons != null) { foreach (BarButton bb in _watConfig.NavBar.Buttons) { AppBarButton appBarMenuItem = new AppBarButton(); appBarMenuItem.Label = bb.Label; appBarMenuItem.Click += appBarMenuItem_Click; ApplicationBar.SecondaryCommands.Add(appBarMenuItem); } } }
private static async Task <WatSchema> GetWatConfigAsync() { // Get a file from the installation folder with the ms-appx URI scheme. var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(WAT_CONFIG_PATH)); using (Stream stream = await file.OpenStreamForReadAsync()) { using (StreamReader sr = new StreamReader(stream)) { string configJSON = sr.ReadToEnd(); return(WatSchema.CreateConfig(configJSON)); } } }
public static async void LoadConfigAsync(WebView currentWebView, CommandBar bottomAppBar) { ResourceLoader resourceLoader = new ResourceLoader(); watConfig = new WatSchema(); mainWebView = currentWebView; //Load WatConfig try { watConfig = await WatConfig.GetWatConfigAsync(); mainWebView.Navigate(new Uri(watConfig.BaseURLString)); } catch (Exception ex) { AppLogs.WriteError("WatConfigLoadWatConfig", ex); Debug.WriteLine(ex); DisplayPackageImageToast.Display(resourceLoader.GetString("LoadError")); #if WINDOWS_PHONE_APP App.Current.Exit(); #endif } //Load AppBar try { if (watConfig != null) { var watAppBar = new WatAppBar(watConfig, bottomAppBar, mainWebView); } } catch (Exception ex) { AppLogs.WriteError("WatConfigLoadAppBar", ex); Debug.WriteLine(ex); DisplayPackageImageToast.Display(resourceLoader.GetString("LoadAppBarError")); } RegisterForShare(); }