如何使用 Binding="{Binding}" 以编程方式创建 DataTrigger?

How to create a DataTrigger programatically with Binding="{Binding}"?

C# 代码中这个 DataTrigger 的等价物是什么?

<DataTrigger
  Binding="{Binding}"
  Value="{x:Null}">
    <Setter
      Property=SomeProperty
      Value=SomeValue />
</DataTrigger>

我对如何创建 Binding 持怀疑态度。这是正确的吗?

var trigger = new DataTrigger();
trigger.Value = null;
// Is this sufficient?
trigger.Binding = new Binding();
// Code to create the setter
// ...

这相当于您的 XAML:

var trigger = new DataTrigger()
{
    Value = null,
    Binding = new Binding(".")
};
trigger.Setters.Add(new Setter() { Property = SomeProperty, Value = SomeValue });