WpfResourceApp2( WPF )

Objectives:

  • Window Code-Behind :
    •  object.SetResourceReferences(BackGroundproperty, "background")
    • object.Backgound= (Brush) container.Resouces["background"];
    • object.Backgound= (Brush) container.FindResouce["background"];
  • Dependency,  "BackGroundproperty"; Key "dynBrush"

  • x:UID is similar to

Step:1 Create a New project

Step:2 Edit Codes in MainWindow.xaml and MainWindow.xaml.cs

Step:3 Runtime Views

 

a) Testing FindResource: Button's default background
SolidColorBrush azureBrush = Brushes.Azure;
App application = (App)Application.Current;
application.Resources.Add("background", azureBrush);
btn1.Background = (SolidColorBrush)btn1.FindResource("background");

b) Testing Brushes.Red;

c) Testing:  btn1.SetResourceReference(BackgroundProperty, "dynBrush")

c) Testing "findRes" (FindResource)