using System.Windows;
using System.Windows.Controls;

namespace _4_WPF资源_2资源层次;

/// <summary>
///     Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        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}");
    }
}