WPF DataContext在看似相同的情况下的工作方式不同

use*_*759 5 c# data-binding wpf datacontext

我有以下资源:

<Window.Resources>
    <SolidColorBrush x:Key="b" Color="{Binding B}" />
    <my:C x:Key="c" Prop="{Binding Source={StaticResource b}}" />
    <my:C x:Key="d" Prop="{Binding A}" />
    <Ellipse x:Key="e" Fill="{Binding A}" />
    <Ellipse x:Key="f">
        <Ellipse.Fill>
            <SolidColorBrush Color="{Binding B}" />
        </Ellipse.Fill>
    </Ellipse>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

我的窗口有一个声明如下的数据上下文:

<Window ... DataContext="{my:Context}" ...>
Run Code Online (Sandbox Code Playgroud)

自定义类C和Context定义如下:

public class Context : MarkupExtension
{
    public Brush A { get; } = Brushes.Blue;
    public Color B { get; } = Colors.Red;

    public override object ProvideValue(IServiceProvider serviceProvider) => this;
}

public class C : DependencyObject
{
    public static readonly DependencyProperty PropProperty = DependencyProperty.Register("Prop", typeof(Brush), typeof(C));
    public Brush Prop { get { return (Brush)GetValue(PropProperty); } set { SetValue(PropProperty, value); } }
}
Run Code Online (Sandbox Code Playgroud)

现在,我使用我的数据上下文和绑定的方式看起来与我非常相似,但如果我使用以下代码检查我的资源(在按钮单击处理程序内)

MessageBox.Show("f: " + ((FindResource("f") as Ellipse).Fill?.ToString() ?? "null"));
MessageBox.Show("e: " + ((FindResource("e") as Ellipse).Fill?.ToString() ?? "null"));
MessageBox.Show("d: " + ((FindResource("d") as C).Prop?.ToString() ?? "null"));
MessageBox.Show("c: " + ((FindResource("c") as C).Prop?.ToString() ?? "null"));
MessageBox.Show("b: " + (FindResource("b") as SolidColorBrush).Color.ToString());
Run Code Online (Sandbox Code Playgroud)

我得到这个结果:

f: #00FFFFFF
e: null
d: null
c: #FFFF0000
b: #FFFF0000
Run Code Online (Sandbox Code Playgroud)

即只有最后两个看似正确.这可能是什么原因?