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

RadMenuItem is used to present menu

0 Answers 58 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vikram
Top achievements
Rank 1
Vikram asked on 20 Oct 2013, 04:45 PM
<Style TargetType="{x:Type telerik:RadMenuItem}">
    <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
    <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
    <Setter Property="Background" Value="{StaticResource ContextMenuBackground}"/>
    <Setter Property="Foreground" Value="{StaticResource ContextMenuForeground}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type telerik:RadMenuItem}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition />
                    </Grid.RowDefinitions>
 
                    <Border x:Name="Border"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding Background}"
                        BorderThickness="2"
                        CornerRadius="5">
 
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"
                                              MinWidth="17"
                                              SharedSizeGroup="Icon" />
                                <ColumnDefinition Width="Auto" MinWidth="5"
                                              SharedSizeGroup="Name" />
                                <ColumnDefinition MinWidth="5" Width="Auto"
                                              SharedSizeGroup="Shortcut" />
 
                                <ColumnDefinition MinWidth="10" Width="Auto"
                                              SharedSizeGroup="Arrow" />
                            </Grid.ColumnDefinitions>
 
 
                            <ContentPresenter x:Name="Icon"
                                          Margin="4,0,6,0"
                                          VerticalAlignment="Center"
                                          ContentSource="Icon" />
this piece of code is used to override the menuitem style and set foreground property
<ContentPresenter x:Name="HeaderHost"
                                          Grid.Column="1"
                                          Margin="{TemplateBinding Padding}"
                                          ContentSource="Header"
                                          RecognizesAccessKey="True" >
 
                                <ContentPresenter.Resources>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
                                            <Setter Property="FontSize" Value="11"/>
                                            <Setter Property="FontFamily" Value="Arial Unicode MS"/>
                                            <Style.Triggers>
                                                <Trigger Property="controls:TextBlockService.IsTextTrimmed" Value="True">
                                                    <Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
 
                                </ContentPresenter.Resources>
                                </ContentPresenter>
 
 
 
 
 
 
 
                            <TextBlock x:Name="ShortCuts" Grid.Column="3" Margin="{TemplateBinding Padding}" >
                            </TextBlock>
 
 
 
 
 
                            <Popup x:Name="SubMenuPopup"
                               AllowsTransparency="true"
                               Focusable="false" Grid.IsSharedSizeScope="True"
                               IsOpen="{Binding Path=IsSubmenuOpen,
                                                RelativeSource={RelativeSource TemplatedParent}}"
                               Placement="Right"
                               PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                               VerticalOffset="-3">
                                <Grid x:Name="SubMenu">
                                    <Border x:Name="SubMenuBorder"
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="Gray"
                                        BorderThickness="1"
                                        CornerRadius="5">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                    </Border>
                                </Grid>
                            </Popup>
                        </Grid>
                    </Border>
this separator property is set, because of this property i am getting on extra row in the Rad Menu Item
<Rectangle x:Name="Separator" Grid.Row="1"
                                Height="1" Visibility="Collapsed" 
                                Fill="{DynamicResource GridView_GridLinesItemVertical}" />
 
 
 
 
 
 
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="attachedBehaviors:MenuItemHasSeparatorBehavior.HasSeparator" Value="True">
                        <Setter TargetName="Separator" Property="Visibility" Value="Visible"/>
                    </Trigger>
 
                    <Trigger Property="Role" Value="TopLevelHeader">
                        <Setter Property="Margin" Value="2" />
                        <Setter Property="Padding" Value="6,3,6,3" />
                        <Setter TargetName="SubMenuPopup" Property="Placement" Value="Bottom" />
 
 
                    </Trigger>
 
                    <Trigger Property="Role" Value="TopLevelItem">
                        <Setter Property="Margin" Value="2" />
                        <Setter Property="Padding" Value="6,3,6,3" />
 
                    </Trigger>
 
                    <Trigger Property="Role" Value="SubmenuHeader">
                        <Setter Property="DockPanel.Dock" Value="Top" />
                        <Setter Property="Padding" Value="0,2,0,2" />
 
 
                    </Trigger>
 
                    <Trigger Property="Role" Value="SubmenuItem">
                        <Setter Property="DockPanel.Dock" Value="Top" />
                        <Setter Property="Padding" Value="0,2,0,2" />
 
                    </Trigger>
 
 
 
 
                    <Trigger Property="Icon" Value="{x:Null}">
                        <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
                    </Trigger>
 
                    <Trigger Property="IsChecked" Value="true">
                        <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
                    </Trigger>
 
                    <Trigger SourceName="SubMenuPopup" Property="AllowsTransparency" Value="true">
                        <Setter TargetName="SubMenu" Property="Margin" Value="2" />
                        <Setter TargetName="SubMenu" Property="SnapsToDevicePixels" Value="true" />
                        <Setter TargetName="SubMenuBorder" Property="BitmapEffect" Value="{DynamicResource PopupDropShadow}" />
                    </Trigger>
 
 
 
 
                    <Trigger Property="IsHighlighted" Value="true">
                        <Setter TargetName="Border" Property="Background" Value="{StaticResource BR_Menu_Highlight}" />
                        <Setter Property="Foreground" Value="{StaticResource BR_SE_White}" />
                        <Setter TargetName="ShortCuts" Property="Foreground" Value="{StaticResource BR_SE_White}" />
 
 
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        <Setter TargetName="ShortCuts" Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
RadContextMenu
<Style TargetType="{x:Type telerik:RadContextMenu}">
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Background" Value="{StaticResource ContextMenuBackground}"/>
    <Setter Property="FontSize" Value="11"/>
    <Setter Property="FontFamily" Value="Arial Unicode MS"/>
 
    <Setter Property="Grid.IsSharedSizeScope" Value="True"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type telerik:RadContextMenu}">
 
 
 
 
                <Border x:Name="Border"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{StaticResource ContextMenuBorderBrush}"
                        BorderThickness="1"
                        CornerRadius="5">
 
 
 
 
                    <StackPanel ClipToBounds="True"
                                IsItemsHost="True"
 
 
                        Orientation="Vertical" />
                </Border>
            </ControlTemplate>
 
        </Setter.Value>
    </Setter>
</Style>

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Vikram
Top achievements
Rank 1
Share this question
or