private void RightDriveToolBar_PreviewMouseDown(object sender, MouseButtonEventArgs e) { int i = 0; if (e.LeftButton == MouseButtonState.Pressed) { string ButName = e.Source.ToString().Substring(32, 1); if (e.Source.ToString().Contains("System.Windows.Controls")) { foreach (var citem in RightDriveComboBox.Items) { if (citem.ToString().Substring(0, 1) == ButName) { RightDriveComboBox.SelectedIndex = i; } i++; } } } }
Button But = new Button(); StackPanel ButStackPanel = new StackPanel(); Image ButImage = new Image(); TextBlock textBlock1 = new TextBlock(); ButImage.Source = new BitmapImage(new Uri("g:/Reinstall/Icons/105.png")); ButImage.Width = 16; textBlock1.TextAlignment = TextAlignment.Center; textBlock1.Text = drive; ButStackPanel.Orientation = Orientation.Horizontal; ButStackPanel.Children.Add(ButImage); ButStackPanel.Children.Add(textBlock1); But.Content = ButStackPanel; LeftDriveToolBar.Items.Add(But);
Button Btn = new Button(); //set properties here //... //and the magic comes here: Btn.Click += new RoutedEventHandler(ToolbarBtn_Click); //and the subroutine which void ToolbarBtn_Click(object sender, RoutedEventArgs e) { //your code }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)