using System; using System.Collections.Generic; using System.Linq; 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.Navigation; using System.Windows.Shapes; using System.IO; namespace WpfResourceAPP2 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { SolidColorBrush beigeBrush = Brushes.Beige; public MainWindow() { InitializeComponent(); SolidColorBrush azureBrush = Brushes.Azure; App application = (App)Application.Current; application.Resources.Add("background", azureBrush); // Default Button Background btn1.Background = (SolidColorBrush)btn1.FindResource("background"); } private void lbColor_SelectionChanged(object sender, SelectionChangedEventArgs e) { SolidColorBrush custom = Brushes.Blue; // System.Windows.Controls.ListBoxItem:Brushes.Red; string strColor; string str1; strColor = lbColor.SelectedValue.ToString(); str1 = strColor.Remove(0, 45); MessageBox.Show(str1); /* if(str1.Equals("Red")) { btn1.Background = Brushes.Red; } * */ switch (str1) { case "Red": btn1.Background = Brushes.Red; break; case "Blue": btn1.Background = Brushes.Blue; break; case "Beige": btn1.Background = Brushes.Beige; break; case "setRef": // btn1.Background = Brushes.Blue; btn1.SetResourceReference(BackgroundProperty, "dynBrush"); break; case "findRes": // btn1.Background = Brushes.Blue; btn1.Background = (Brush)btn1.FindResource("findRes"); break; } } } }