Using DynamicResource Programmetically

Normally you assign resources in XAML by using the StaticResource or DynamicResource extension. But how to do it programmatically?

The static behavior is simple. Just find the resource by using the TryFindResource() method and set it to the property of your choice. But if you want to have it dynamically updated, the following code snipped is your solutions: 

frameworkElement.SetResourceReference(dependencyProperty, resourceKey);