using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Controls.Primitives; using System.Diagnostics; using System.ComponentModel; // using System.Windows.Resources; namespace WpfResourceApp1 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { static Int32 n1 = 0; public MainWindow() { InitializeComponent(); // Dynamic Resopurces SP1.Resources.Add("background", Brushes.DarkTurquoise); // statusText.Text ="App:Status "+ Application.Current.ShutdownMode.ToString(); createNew.Background = (Brush)createNew.FindResource("background"); createNew.Click += new RoutedEventHandler(newWindowButton_Click); closeWindow.Click += new RoutedEventHandler(shutdownButton_Click); Grid.SetColumn(createNew, 1); // winMenu.SubmenuOpened += new RoutedEventHandler(winMenu_SubmenuOpened); Closing += MainWindow_Closing; App_Shutdown.Click += new RoutedEventHandler(Shutdown_All); } public void winMenu_SubmenuOpened(object sender, RoutedEventArgs e) { winMenu.Items.Clear(); foreach (Window window in Application.Current.Windows) { MenuItem item = new MenuItem(); item.Header = window.Title; item.Click += winMenuItem_Click; item.Tag = window; item.IsChecked = window.IsActive; winMenu.Items.Add(item); } } public void winMenuItem_Click(object sender, RoutedEventArgs e) { // Will activate newly created window with // indexed by window collection Window window = (Window)((MenuItem)sender).Tag; window.Activate(); statusText.Text = window.Title.ToString(); } public void newWindowButton_Click(object sender, RoutedEventArgs e) { Window window = new Window(); window.Title = "Window No:1"+ (n1++) ; window.Width = 200; window.Height = 100; window.Show(); statusText.Text = Application.Current.ShutdownMode.ToString(); } private void shutdownButton_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } void MainWindow_Closing(object sender, CancelEventArgs e) { if (MessageBox.Show("Do you really want to shut down?", "Shutting Down", MessageBoxButton.YesNo) == MessageBoxResult.No) { e.Cancel = true; } } private void Shutdown_All(Object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } private void button1_Click(object sender, RoutedEventArgs e) { // button1.Background = Brushes.SeaGreen; button1.Resources["statBrush1"] = Brushes.DarkTurquoise; statusText.Text = sender.ToString() + button1.Name.ToString(); } private void button2_Click(object sender, RoutedEventArgs e) { // button2.Background = Brushes.SeaGreen; //toggle statusText.Text = Application.Current.Dispatcher.ToString(); if (button2.Resources["statBrush2"] == Brushes.DarkTurquoise) { button2.Resources["statBrush2"] = Brushes.YellowGreen; } else { button2.Resources["statBrush2"] = Brushes.DarkTurquoise; } } } }