Hi there. I'm using the Microsofts RibbonControlLibrary for a Ribbonmenu with several RibbonCommands. I have a TabControl that should contain tabs for each ribbon button pressed. E.g. I click on RibbonCommand 2, I want a tab called "Tab2" be created, if it is not already present in the TabControl, otherwise it should be focused.
I've already implemented http://www.codeproject.com/KB/WPF/WpfTabCloseButton.aspx, which are very nice.
I think I still don't get the event mechanism of WPF quite right. My code strongly adapted the sample project of the Ribboncontrol.
This is how I implemented the Command:
<Window.CommandBindings>
<CommandBinding Command="me:AppCommands.Protokoll" Executed="RibbonButton_Click" />
</Window.CommandBindings>
The button inside the RibbonControl looks like the following.
<r:RibbonButton Command="me:AppCommands.Protokoll" />
AppCommands.cs
public class AppCommands
{
public static RibbonCommand Protokoll
{
get { return (RibbonCommand)Application.Current.Resources["ProtokollCommand"]; }
}
}
ResourceDictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary">
<r:RibbonCommand x:Key="ProtokollCommand"
LabelTitle="foo"
ToolTipTitle="foo"
ToolTipDescription="foo" />
</ResourceDictionary>
What I now want to write is a Method that creates a Tab for each button click, where as the created tabpage contains specific usercontrols. I do not know, how to best implement the mapping between the CommandButtons and the Tabs. I think its best to use just one click-eventhandler rather than a eventhandler for each button. Questions:
1) How can I find out which unique button raised the event? I've only managed to get the information in the ResourceDictionary. Unfortunatly there is no such property as uniqueID or something like this. I've done this with:
private void RibbonButton_Click(object sender, RoutedEventArgs e)
{
// ((Microsoft.Windows.Controls.Ribbon.RibbonCommand)(((System.Windows.Controls.Button)(e.OriginalSource)).Command))
}
I do not want to create a mapping based on a property like LabelTitle that is supposed for display.
2) I've found this http://stackoverflow.com/questions/2277464/wpf-c-how-does-one-reference-tabitems-inside-a-tabcontrol which showed me how to query the Items collection of the TabControl. Is that a good attempt or is there a better one?
3)
How should I create the mapping between the RibbonCommand and the TabPage + Controls that should be displayed. Of course I could use a Dictionary like
Dictionary<String, fooContainer>
// ...
public class fooContainer()
{
public String TabHeaderString {get;set;}
// other properties
}
Or does WPF present a better approach with these ResourceDictionaries, that I haven't understood till now.