diff --git a/4-WPF资源-2资源层次/MainWindow.xaml b/4-WPF资源-2资源层次/MainWindow.xaml
index d053d55..0f7c312 100644
--- a/4-WPF资源-2资源层次/MainWindow.xaml
+++ b/4-WPF资源-2资源层次/MainWindow.xaml
@@ -3,10 +3,45 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:_4_WPF资源_2资源层次"
mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
-
+ Icon="public/003540AH4M72.jpg" Title="_4_WPF资源_2资源层次" Height="450" Width="800">
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/4-WPF资源-2资源层次/MainWindow.xaml.cs b/4-WPF资源-2资源层次/MainWindow.xaml.cs
index 547469f..1c0dacf 100644
--- a/4-WPF资源-2资源层次/MainWindow.xaml.cs
+++ b/4-WPF资源-2资源层次/MainWindow.xaml.cs
@@ -1,18 +1,10 @@
-using System.Text;
-using System.Windows;
+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;
namespace _4_WPF资源_2资源层次;
///
-/// Interaction logic for MainWindow.xaml
+/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
@@ -20,4 +12,14 @@ public partial class MainWindow : Window
{
InitializeComponent();
}
+
+ private void FindResource_OnClick(object sender, RoutedEventArgs e)
+ {
+ var button = (Button)sender;
+ var tryFindResource = button.TryFindResource("BunnyImageBrush");
+ Console.WriteLine($"尝试查找资源,找不到返回null:{tryFindResource}");
+
+ var findResource = button.FindResource("BunnyImageBrush");
+ Console.WriteLine($"尝试查找资源,找不到报错:{findResource}");
+ }
}
\ No newline at end of file