2025-01-12 16:20:47 +08:00
|
|
|
|
using System.Windows;
|
2025-01-10 12:14:50 +08:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
2025-01-10 12:16:43 +08:00
|
|
|
|
namespace _4_WPF资源_2资源层次;
|
2025-01-10 12:14:50 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-12 16:20:47 +08:00
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
2025-01-10 12:14:50 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2025-01-12 16:20:47 +08:00
|
|
|
|
|
|
|
|
|
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}");
|
|
|
|
|
}
|
2025-01-10 12:14:50 +08:00
|
|
|
|
}
|