private void CreateSampleMenuItem(MenuItem parentMenu, Sample sample) { MenuItem sampleitem = new MenuItem() { Header = sample.Name, ToolTip = new TextBlock() { Text = sample.Description, MaxWidth = 300, TextWrapping = TextWrapping.Wrap } }; parentMenu.Items.Add(sampleitem); sampleitem.Click += (s, e) => { sampleitem_Click(sample, s as MenuItem); }; }
private void sampleitem_Click(Sample sample, MenuItem menu) { var c = sample.UserControl.GetConstructor(new Type[] { }); var ctrl = c.Invoke(new object[] { }) as UIElement; SampleContainer.Child = ctrl; if (currentSampleMenuItem != null) currentSampleMenuItem.IsChecked = false; menu.IsChecked = true; currentSampleMenuItem = menu; StatusBar.DataContext = sample; }
private void sampleitem_Click(Sample sample, MenuItem menu) { var isSampleAvailable = true; // Check if sample needs SDK installation and if it's available // If build with using Nuget reference, deployment folder is copied under the bin folder // without symbols or other deployable extensions. if (sample.RequiresSymbols && !(CheckIfHasDeploymentFolder() || CheckIfSdkIsInstalledAndNoDeploymentIsFound())) isSampleAvailable = false; // Check if local server is needed and if it's available if (sample.RequiresLocalServer && !(CheckIfHasDeploymentAndLocalServer() || CheckIfSdkIsInstalledAndNoDeploymentIsFound())) isSampleAvailable = false; if (!isSampleAvailable) { // Todo deploy local server. SampleContainer.Child = new SdkInstallNeeded(); if (currentSampleMenuItem != null) currentSampleMenuItem.IsChecked = false; StatusBar.DataContext = new Sample() { Description = "Sample isn't available.", UserControl = typeof(SdkInstallNeeded)}; return; } var c = sample.UserControl.GetConstructor(new Type[] { }); var ctrl = c.Invoke(new object[] { }) as UIElement; SampleContainer.Child = ctrl; if (currentSampleMenuItem != null) currentSampleMenuItem.IsChecked = false; menu.IsChecked = true; currentSampleMenuItem = menu; StatusBar.DataContext = sample; GC.Collect(); GC.WaitForPendingFinalizers(); }