How do I transform System.Windows.Controls.Button into Fluent.Button?

Mar 16, 2011 at 3:03 AM

In my Project_1, I define two Ribbon content:

    [Export(typeof(IRibbon))]
    public partial class ribbon1 : AbstractRibbon
    {
        public ribbon1()
        {
            Tab_Name = "ViewTree";
            Group_Name = "Category";
            Button_Name = "New Category";
            bt = new System.Windows.Controls.Button();
            bt.Click += new RoutedEventHandler(bt_Click);
        }

        public void bt_Click(object sender, RoutedEventArgs e)
        {
            //call function in my Project_1
        }
    }

    [Export(typeof(IRibbon))]
    public partial class ribbon2 : AbstractRibbon
    {
        public ribbon2()
        {
            Tab_Name = "ViewTree";
            Group_Name = "Category";
            Button_Name = "Delete Category";
            bt = new System.Windows.Controls.Button();
            bt.Click += new RoutedEventHandler(bt_Click);
        }
        public void bt_Click(object sender, RoutedEventArgs e)
        {
            // call function in my Project_1
        }
    }

In my Project_2, I use the reflection method to import all "IRibbon":
        [ImportMany(typeof(IRibbon))]
        private IEnumerable<Lazy<IRibbon>> Ribbons { get; set; }
        .....

So I can get two Ribbon contents, and add Fluent.Tab, Fluent.Group, and Fluent.Button programmatically:

       foreach (var rib in Ribbons)
       {
             // add new Fluent.Tab
                ....
             // add new Fluent.Group
                ....
             // add new Fluent.Button
 
            Fluent.Button Buttons = (Fluent.Button)rib.bt; //throw System.InvalidCastException
}

However, I get a System.InvalidCastException in Fluent.Button Buttons = (Fluent.Button)rib.bt;

How can I transform System.Windows.Controls.Button into Fluent.Button?
Or is this possible to transform System.Windows.Controls.Button into Fluent.Button?