RibbonGroupBox and DataTemplate

Jul 31, 2010 at 12:34 AM

Consider the following scenario:

Fluent app, GroupBox that need to be populated from code.

I've made simple class (i.e. DecoupledButton) that to be used instead of Fluend.Button from the rest of my app.

I've made a data template for that class, the DataType of the template is setted to DecoupledButton. The data template takes that DecoupledButton objects and "transforms" them in Flluent.Button.

 If i define a button of type DecoupledButton in XAML, the template is applied, and the button shows in the group.

But if i try to use <RibbonGroupBox>.Items.Add method to add the button from code behind, an exception is thrown (Unable to cast object of type 'DecoupledButton' to type 'System.Windows.Media.Visual'.).

How can I add some object to GroupBox' items collection from code behind and to apply the data templates by type?

Any help is appriciated, thanks in advance!