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

Dynamically created menu woes

5 Answers 126 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dasha
Top achievements
Rank 1
Dasha asked on 01 Aug 2012, 12:03 PM
Hello,

I'm a big fan of Telerik, especially for how easy and clean are all the controls and their integration.  I was very surprised to run into as much trouble as I did when trying to dynamically create a Silverlight RadMenu and add it to a StackPanel.  We've been adding Buttons to the StackPanel without a single problem, so I thought what can be difficult about adding a RadMenu?  For some reason I can't get it to happen!  I can't find any helpful examples, so maybe you could help me out.  This is what I'm trying to do:

StackPanel spButton = new StackPanel();
TextBlock txtButtonText = new TextBlock();
Image img = new Image();
Double BtnWidth = 125;
Double BtnHeight = 25;
 
StackPanel ganttMainToolBar = null;
ganttMainToolBar = new StackPanel();
ganttMainToolBar.Name = "ganttMainToolBar";
ganttMainToolBar.Orientation = Orientation.Horizontal;
ganttMainToolBar.VerticalAlignment = VerticalAlignment.Center;
ganttMainToolBar.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
ganttMainToolBar.Width = _ganttWidth - 5;
ganttMainToolBar.Height = BtnHeight;
ganttMainToolBar.SetValue(Grid.RowProperty, 0);
ganttMainToolBar.SetValue(Grid.ColumnProperty, 0);
ganttMainToolBar.Margin = new Thickness(5, 5, 0, 5);
ganttMainToolBar.Tag = "100";
 
RadMenu radMenu = new RadMenu();
radMenu.Name = "radMenu";
radMenu.Tag = "111";
radMenu.Height = BtnHeight;
radMenu.Width = 200;
StyleManager.SetTheme(radMenu, new VistaTheme());
 
RadMenuItem topLevelItem = new RadMenuItem();
topLevelItem.Name = "file";
topLevelItem.Header = "File";
topLevelItem.Tag = "1111";
topLevelItem.Height = BtnHeight;
topLevelItem.Width = 100;
StyleManager.SetTheme(topLevelItem, new VistaTheme());
radMenu.Items.Add(topLevelItem);
 
ganttMainToolBar.Children.Add(radMenu);
 
#region new item
Button btnNewButton = new Button();
btnNewButton.Name = "AddNewItemButton";
spButton = new StackPanel();
spButton.Orientation = Orientation.Horizontal;
spButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
spButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;
img = new Image();
img.Source = new BitmapImage(new Uri("add2.png", UriKind.Relative));
img.Width = 16; img.Height = 16;
img.Margin = new Thickness(5, 0, 5, 0);
spButton.Children.Add(img);
txtButtonText = new TextBlock();
txtButtonText.Text = "Add New Item";
txtButtonText.Margin = new Thickness(5, 0, 5, 0);
spButton.Children.Add(txtButtonText);
btnNewButton.Content = spButton;
btnNewButton.Margin = new Thickness(0, 0, 0, 0);
btnNewButton.Tag = "104";
btnNewButton.Click += new RoutedEventHandler(GanttTable_AddTasks);
btnNewButton.IsEnabled = DisableBtnForSnapShot();
btnNewButton.Width = BtnWidth;
ganttMainToolBar.Children.Add(btnNewButton);
ToolTipService.SetToolTip(btnNewButton, "Add New Item");
#endregion
 
 
LayoutRoot.Children.Add(ganttMainToolBar);


All the Buttons show up ok, but not the RadMenu!  The most I can get to happen is to get the space allocated on the StackPanel, i.e. all the buttons are shifted to the right, as if something invisible is there.

Please help!

5 Answers, 1 is accepted

Sort by
0
Dasha
Top achievements
Rank 1
answered on 01 Aug 2012, 02:50 PM
I also put together a simple project where I try to create a static menu without any luck either.  I'm obviously missing some vital piece, but I can't figure out what it is!  We're running on Silverlight 4, would that make a difference?  Can I sent the project to you? I can't seem to attach it to the post.
0
Rosen Vladimirov
Telerik team
answered on 03 Aug 2012, 05:40 AM
Hi,

We have tested this scenario based on your code but we were unable to reproduce the problem. I`m sending you the simple project we used and how the output looks like. I tested it with Silverlight 4 and Silverlight 5 and it is working fine.
I noticed that the problem may occur if the Width and Height of the components are not set correctly (too low or too large values for different controls). Also the UserControl width and height should be set accordingly. If you check the project I`m sending, you`ll notice that we are using hard-coded values for these properties. It is a good idea to check the values you are using and maybe to use XAML Spy after starting the application to check if all controls are populated. Also you may check the margins - too large values can cause such strange behaviour.

Please try this project and inform us if you face any problems.

Greetings,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dasha
Top achievements
Rank 1
answered on 03 Aug 2012, 07:06 AM
Hello Rosen,

Thank you so much for your reply!  I tested your solution, and I'm still seeing the same type of result, see my attached image.  Makes me think I'm using the wrong dll, could that be the reason?  I didn't change anything in your same except reassign the Telerik assembly references.  I'm using the dll's from the RadControls_for_Silverlight4_2012_2_0725_DEV_hotfix.  Any other ideas about what could be wrong in my environment?
0
Dasha
Top achievements
Rank 1
answered on 03 Aug 2012, 02:26 PM
I figured it out! I was in fact using the wrong dll's!  I was using the dlls from the "RadControls_for_Silverlight4_2012_2_0725_DEV_hotfix\Binaries.NoXaml" folder, which were wrong.  I needed to use the "RadControls_for_Silverlight4_2012_2_0725_DEV_hotfix\Binaries" folder.  Now everything is working properly.  Thank you so much for the help.
0
Rosen Vladimirov
Telerik team
answered on 03 Aug 2012, 02:33 PM
Hi Dasha,

It looks like you are using the dll files from Binaries.noXAML and this is preventing the RadMenu from showing. In this case you have two options:
1) use the dlls from Binaries directory
2) when you are using these binaries you have to add theme for the specific control. In this case you have to add to your project the Telerik.Windows.Controls.Navigation.xaml file from Theme.Implicit directory (you`ll have to choose one of the themes) and after that add the following piece of code in your App.xaml file:
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Telerik.Windows.Controls.Navigation.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

To be more clear I`m sending you the previous example with added Telerik.Windows.Controls.Navigation.xaml file. Please test it - it should be working now.

Don`t hesitate to contact us in case of any problems and concerns.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Menu
Asked by
Dasha
Top achievements
Rank 1
Answers by
Dasha
Top achievements
Rank 1
Rosen Vladimirov
Telerik team
Share this question
or