Our own example in XAML and C# looked like this:
<ItemsControl Style="{DynamicResource POSDatesTimesButtonItemsControlStyle}"
FrameworkElementFactory itemsControlElement = new FrameworkElementFactory(typeof(ItemsControl));
itemsControlElement.SetResourceReference(ItemsControl.StyleProperty,
"POSDatesTimesButtonItemsControlStyle");
itemsControlElement.SetResourceReference(ItemsControl.StyleProperty,
"POSDatesTimesButtonItemsControlStyle");