This is a migrated thread and some comments may be shown as answers.

RadContextMenu/RadMenu DataTemplate Issue

1 Answer 187 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Shlomi
Top achievements
Rank 1
Shlomi asked on 18 Jul 2012, 04:11 AM
Hi

I am using a system in which I supply an object with a DataTepmlate.
The object has an interface which has a DataTemplate property (dynamic DataTemplate)

I apply an ItemTemplateSelector which returns the 'DataTemplate' Property

I also have a collection (Obserable) for these objects...

I Try to implement a SplitButton with a DropDownContent but I have 2 main problems.
1) The Menu appears but a MenuItem with childs only shows the Arrow but will not open not with click and with hover.
2) The MenuItems show`s an inner button, liks there the MenuItem and a RadButton inside....

This is my XAML:
SplitButton whereas local:SplitButtonVisualCommand is my business object.
<DataTemplate DataType="{x:Type local:SplitButtonVisualCommand}">
    <telerik:RadSplitButton Command="{Binding Command}" 
                            CommandParameter="{Binding GetParameters}"
                            Opacity="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource DisabledWorkAround}}"
                            IsToggle="{Binding RelativeSource={RelativeSource Self}, Path = IsOpen}"
                            DropDownContent="{Binding Childs}"   
                            DropDownContentTemplateSelector="{StaticResource VisualTempSelector}">
        <telerik:RadSplitButton.Content>
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding Image}" Margin="0 0 2 0"/> 
                <TextBlock Text="{Binding Caption}" />
            </StackPanel>                
        </telerik:RadSplitButton.Content>            
    </telerik:RadSplitButton>
</DataTemplate>
.
The 'Childs' DropDownContent is an Observable collection which returns the following DataTemplate:
(The Childs object also implement the 'DataTemplae' Property....)
<DataTemplate  DataType="{x:Type VisualCommands:VisualCommandCollection}">
    <telNav:RadContextMenu  ClickToOpen="False"
                            ItemsSource="{Binding}" 
                            ItemTemplateSelector="{StaticResource VisualTemplateSelector}"/>
</DataTemplate>

As you can see, it shows itself as a RadContextMenu (can be altered to RadMenu...) and sets itself as the ItemsSource as it holds the following Business Objects:

<DataTemplate DataType="{x:Type local:ContextMenuVisualCommand}">
    <telNav:RadMenuItem Header="{Binding Caption}"
                        Icon="{Binding Image}"
                        ItemsSource="{Binding Childs}"     
                        ItemTemplateSelector="{StaticResource VisualTemplateSelector}"
                        Command="{Binding Command}" 
                        CommandParameter="{Binding GetParameters}"
                        Opacity="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource DisabledWorkAround}}">
    </telNav:RadMenuItem>
</DataTemplate>

local:ContextMenuVisualCommand are the same as local:SplitButtonVisualCommand , they just have a different DataTemplate.
The present as RadMenuItem....

I`v attached an Image to visualize it...

The 1st menu item knows it has childs, but wont show them.
Also, what is this strange box inside the MenuItem? does it inhrit from the SplitButton?

I also know that
ItemTemplateSelector.SelectTemplate 
gets called Twice for each sub item in the SplitButton DropDownContent, this might explain the extra box inside the MenuItem.
This is strange becuase 'SelectTemplate' is called once for all other Business objects.

Also, 'SelectTemplate' is not called for the MenuItem inside the 1st MenuItem, which has logic since it never 'Show' it...
Thanks!
Shlomi.


1 Answer, 1 is accepted

Sort by
0
Shlomi
Top achievements
Rank 1
answered on 18 Jul 2012, 06:47 AM
Well... I found my error.

You cant represent an item`s DataTemplate as a MenuItem since the RedMenu shows it inside a MenuItem.

How can I override this behavior?
Tags
ContextMenu
Asked by
Shlomi
Top achievements
Rank 1
Answers by
Shlomi
Top achievements
Rank 1
Share this question
or