private static void OnCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { NavigationPaneButton b = d as NavigationPaneButton; OnCheckStateChanged(d, e); if ((bool)e.NewValue) { b.RaiseEvent(new RoutedEventArgs(ToggleButton.CheckedEvent)); } else { b.RaiseEvent(new RoutedEventArgs(ToggleButton.UncheckedEvent)); } }
private void Button_Click(object sender, RoutedEventArgs e) { // MessageBox.Show(this.navigationPane.SelectedItemSubItems.Count().ToString()); NavigationPaneItem item = new NavigationPaneItem(); item.Header = newItemName.Text; item.Content = newItemContents.Text; StackPanel sp = new StackPanel(); item.Content = sp; item.SubItems = new System.Collections.ObjectModel.ObservableCollection<NavigationPaneButton>(); NavigationPaneButton btn = new NavigationPaneButton(); btn.Content = "123"; btn.Name = "实物"; btn.Click += new RoutedEventHandler(NavPaneButton_Click); //item.SubItems.Insert(0, btn); sp.Children.Add(btn); btn.VerticalAlignment = System.Windows.VerticalAlignment.Top; NavigationPaneButton btn1 = new NavigationPaneButton(); btn1.Content = "1232"; btn1.Name = "成果"; btn1.Click += new RoutedEventHandler(NavPaneButton_Click); //item.SubItems.Insert(0, btn); sp.Children.Add(btn1); btn.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; item.Image = new BitmapImage(new Uri(@"pack://application:,,,/NavigationPaneDemo;component/Resources/folderopen.ico")); navigationPane.Items.Add(item); item.IsExcluded = newItemExcluded.IsChecked.Value; }