I have a RadTabControl and I want to enable the drop-down button "WhenNeeded" so that users can easily access the buttons in the tab control. I have three templates for the tab items (RadTabItem) which means I should have 3 templates as well for the drop-down buttons that appear in the drop-down list.
There is a field called ItemDropDownContentTemplateSelector in RadTabControl and I created a template selector class like so:
public class DropDownDisplayModeTemplateSelector: DataTemplateSelector
{
public override DataTemplate
SelectTemplate(object item, DependencyObject container)
{
try
{
FrameworkElement element = container as FrameworkElement;
Console.WriteLine("DropDownDisplayModeTemplateSelector: " + element.GetType().Name);
if (element != null && item != null && item is TabItem)
{
TabItem tabItem = item as TabItem;
switch (tabItem.TabItemStyle)
{
case TabItemStyle.Title:
return element.FindResource("TitleDropDownModeDataTemplate") as DataTemplate;
case TabItemStyle.Button:
return element.FindResource("ButtonDropDownModeDataTemplate") as DataTemplate;
case TabItemStyle.GroupOfButtons:
return element.FindResource("GroupOfButtonsDropDownModeDataTemplate") as DataTemplate;
default:
return element.FindResource("ButtonDropDownModeDataTemplate") as DataTemplate;
}
}
else
return null;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
}
However, finding the DataTemplates with element.FindResource() method doesn't work because the container element is of type "DropDownMenuItem" which of course is not the element where my data templates are defined.
I have them defined in the top level Grid element like so:
<Grid>
<Grid.Resources>
<ResourceDictionary>
<DataTemplate x:Key="TitleDropDownModeDataTemplate">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="4"
Grid.Column="1"
Text="TitleDropDownModeDataTemplate" />
</DataTemplate>
<DataTemplate x:Key="ButtonDropDownModeDataTemplate">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="4"
Grid.Column="1"
Text="ButtonDropDownModeDataTemplate" />
</DataTemplate>
<DataTemplate x:Key="GroupOfButtonsDropDownModeDataTemplate">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="4"
Grid.Column="1"
Text="GroupOfButtonsDropDownModeDataTemplate" />
</DataTemplate>
<models:DropDownDisplayModeTemplateSelector x:Key="myDropDownDisplayModeTemplateSelector"/>
</ResourceDictionary>
</Grid.Resources>
<telerik:RadTabControl
ItemsSource="{Binding TabItems}"
ItemDropDownContentTemplateSelector="{StaticResource myDropDownDisplayModeTemplateSelector}"
DropDownDisplayMode="WhenNeeded">
</Grid>
In this case what should I do, hack the way top to the Grid's resources or I have done something wrong in defining my drop-down template selector?