I Have code like this
<Style>
....................................................................
<
Grid x:Name="MenuGrid" Height="25" Margin="0,0,0,0" Opacity="1" Background="Black">
<telerikNavigation:RadMenu Background="#304256" Name="RadMenu1">
<telerikNavigation:RadMenuItem Header="File" Background="#304256" Foreground="#C0DDF8">
<telerikNavigation:RadMenuItem Header="New Tab" Foreground="#A6C1D9" Background="#35465A">
</telerikNavigation:RadMenuItem>
</telerikNavigation:RadMenuItem>
<telerikNavigation:RadMenuItem Header="Edit" Background="#304256" Foreground="#C0DDF8">
<telerikNavigation:RadMenuItem Header="Copy" Foreground="#A6C1D9" Background="#35465A">
</telerikNavigation:RadMenuItem>
</telerikNavigation:RadMenuItem>
</telerikNavigation:RadMenu>
</Grid>
..................................................................
</Style>
Instead of hardcode like this, i want to create the RadMenu and RadMenuItem in Grid (MenuGrid) at code behind dynamically.
How can i do that? Example code will highly appreciate.
7 Answers, 1 is accepted
RadMenu and RadMenuItems are ItemsControl, that means they are exposing a property -Items, where all the children are stored. To add a new item you just need to call radManu.Items.Add(new RadMenuItem()) method. Attached is a project that you requested.
Sincerely yours,
Kaloyan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Maybe i should let you know where i wan to load the radmenu.
<
UserControl x:Class="TelerikThemingApplication.RadWindowBlend"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mscorlib="clr-namespace:System;assembly=mscorlib"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
Width="400" Height="300">
<UserControl.Resources>
<Style x:Key="DropdownStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.2" To="MouseOver"/>
<VisualTransition GeneratedDuration="0:0:0.1" To="Normal"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:02" Storyboard.TargetName="DropDown" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<EasingDoubleKeyFrame KeyTime="00:00:01" Value="23"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="DropDown">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<telerikNavigation:RadMenu x:Name="radMenu1">
</telerikNavigation:RadMenu >
</Grid>
<Rectangle Fill="#C0DDF8" Stroke="White" StrokeThickness="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Button Height="23" Style="{StaticResource DropdownStyle}" VerticalAlignment="Top"/>
</Grid>
</
UserControl>
I wanted to put the RadMenu where the radMenu1 is.
By using the code you provide, i can create it but it already cover my button.
Sincerely yours,
Kaloyan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
is it do not have a way to insert the radMenu in the grid that i mention?
Greetings,
Kaloyan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The example actually represent the usate of the RadMenu. Find our online example with some related Contextmenu examples and further information. Let us know if any particular case appears.
Best wishes,
Kaloyan
the Telerik team