Some decompilation using ILSpy helped solve this:
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
var style = new Style(typeof (Button));
var brush = new SolidColorBrush(Colors.Blue);
Resources["TheColor"] = brush;
var dynamicResource = new DynamicResourceExtension("TheColor");
var setter = new Setter()
{
Property = Control.BackgroundProperty,
Value = dynamicResource
};
style.Setters.Add(setter);
button1.Style = style;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
var brush = new SolidColorBrush(Colors.Red);
Resources["TheColor"] = brush;
}
}
So interestingly, the Setter.Value expects a value of DynamicResourceExtension. I originally thought that the expression generated by DynamicResourceExtension.ProvideValue() would be what the setter value should take. Anyway, this seems to work.