3-WPF-Order/4-WPF资源-2资源层次/MainWindow.xaml.cs

25 lines
722 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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}");
}
}