I have the following piece of XAML code:
<controlsInputToolkit:ContextMenuService.ContextMenu>
<controlsInputToolkit:ContextMenu
Height="75"
Width="200"
IsOpen="False"
Visibility="Collapsed"
Closed="mnuPopup_Closed"
x:Name="mnuPopup">
<controlsInputToolkit:MenuItem
x:Name="mnuAnswer911Call"
Header="Answer Call"
Click="mnuAnswer911Call_Click"
IsEnabled="True"/>
<controlsInputToolkit:MenuItem
x:Name="mnuHangup911Call"
Header="Hangup call"
Click="mnuHangup911Call_Click"
IsEnabled="True"/>
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
Let's say, based on context, I wanted to add a submenu to the mnuAnswer911Call menu item. How would I go about it?
The Silverlight Context Menu does not support submenus yet. But there are open source alternatives to help you achieve this. Here is one:
www.sl4popupmenu.codeplex.com
Related
I heed to create wizard and in the wizard I have tab control which have to call to the user control according to the context,I need to create the wizard which will able to invoke
different pages according to the user selection ,currently I call to the pages as follows which I think is not the right way,any Idea how should I do it via code (not in the xaml )i.e. according to some decision invoke the suitable page to the tab control.
this is the xaml:
<Border Grid.Column="1" Name="MainBorder">
<TabControl x:Name="MainTabControl" Height="638" VerticalAlignment="Bottom">
<TabItem Visibility="Collapsed" >
<Frame Source="page1.xaml" />
</TabItem>
<TabItem Visibility="Collapsed" >
<Frame Source="page2.xaml"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Step 3">
<TextBlock Text="Page 3"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Step 4">
<TextBlock Text="Page 4"/>
</TabItem>
</TabControl>
</Border>
UPDATE
I was tried in the main window like the following without success
create new tab by code and add to it the page 1 and then add it to the MainTabControl
TabControl tabControl = new TabControl(new Page1());
MainTabControl.add..
.
there is no add in the main tab control
For this scenario, I would use a Frame rather that tabs. The frame allows you to manage the flow of it's content via the NavigationService. You can use Uri's to display a page via the Frame.Source property, or a FrameworkElement via the Frame.Content property. Both are DependencyProperties and can therefore be bound to.
Paul Stovel wrote an excellent blog on this called WPF Navigation. Everything you need to create a wizard from a frame can be found in this blog, including passing values between pages and templating of the Frame to simply handle the display of navigation buttons.
I would agree with Mark, it is a lot easier to use NavigationWindows than TabControls.
I've worked on a lot of interfaces like this and written up some of the basic things with,
WPF Wizards, Part 1
WPF Wizards, Part 2
Then more recently I worked out how to get the styling just right
Styling Wizards
In fact I've released the styling and examples as open source at
WinChrome
There is some simple example code including use of a navigation list to the left with,
WinChrome.Win7Demo
Hope this helps
How can i mark menuitem in Application Bar. I want to get, for example, this:
You can change the template of the MenuItem.Header, as described in this tutorial. For example:
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="AddItem"/>
<!-- a templated menu item -->
<toolkit:MenuItem>
<toolkit:MenuItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Delete Item"/>
<Image Source="Images/appbar.delete.rest.png"/>
</StackPanel>
</toolkit:MenuItem.Header>
</toolkit:MenuItem>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
I'd say it can't be done. The menu items are just calls to functions and can do nothing but show the corresponding text and call the corresponding method when activated. I've found some examples of people hacking extra functionality into them (updating the text or changing the function calls, to some extent), but nothing beyond that would be possible.
Notice that what you can do with the AppBar is limited by the functionality offered by IApplicationBar and, in your case, ApplicationBarMenuItem. And none of them expose anything even close to your requirements.
You can, however, enable and disable menu items, although I don't think that's what you want.
I don't know if this is possible but does anyone know if there is a way to put a user control inside a context menu, I have a dialog for adding items to a list but I would like when I click the add button for the control to be displayed in the context menu instead. (dont like having a lot of dialog's in my app).
Here is what I tried but it doesn't work:
<Button Grid.Column="2" Grid.Row="1" Content="Add Item" HorizontalAlignment="Right">
<Button.ContextMenu>
<ContextMenu>
<MenuItem>
<vm:MyControlView/>
</MenuItem>
</ContextMenu>
</Button.ContextMenu>
</Button>
Is there a way to achieve this? (or something similar)
You could try this link, it looks like you might be able to extend ContextMenu like John Dunn did to meet your needs.
Please forgive this stupid question. (I'm originally an ASP.NET programmer.)
I'm trying to add a telerik context menu to a textbox control in the code behind.
Adding it in the xaml is very easy (this works)
<TextBox AcceptsReturn="True" Text="{Binding Mode=TwoWay, Path=Description}" TextWrapping="Wrap" x:Name="txtIssues" Width="280" Height="100" VerticalScrollBarVisibility="Auto">
<telerikNavigation:RadContextMenu.ContextMenu>
<telerikNavigation:RadContextMenu x:Name="contextMenu"
ItemClick="ContextMenuClick">
<telerikNavigation:RadMenuItem Header="Set Vista as Background" />
<telerikNavigation:RadMenuItem Header="Set Beach as Background" />
<telerikNavigation:RadMenuItem Header="Set Forest as Background" />
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>
</TextBox>
However I would like to completely add the the control from c# code and I can't find a why to add a control to a textbox. I've been looking for something like "txtIssues.Children.Add" but there doesn't seem to be an option.
First its best you understand that you are not adding a control to the TextBox. The RadContextMenu.ContextMenu is not a control it is an attached property.
Funnily enough the Telerik documentation describes adding a context menu to a textbox in C#. See Working with the RadContextMenu. Sometimes "RTM" is actually good advice.
I have the following piece of XAML code:
<controlsInputToolkit:ContextMenuService.ContextMenu>
<controlsInputToolkit:ContextMenu
Height="75"
Width="200"
IsOpen="False"
Visibility="Collapsed"
Closed="mnuPopup_Closed"
x:Name="mnuPopup">
<controlsInputToolkit:MenuItem
x:Name="mnuAnswer911Call"
Header="Answer Call"
Click="mnuAnswer911Call_Click"
IsEnabled="True"/>
<controlsInputToolkit:MenuItem
x:Name="mnuHangup911Call"
Header="Hangup call"
Click="mnuHangup911Call_Click"
IsEnabled="True"/>
<controlsInputToolkit:MenuItem
x:Name="mnuConference911Call"
Header="Conference Call"
Click="mnuConference911Call_Click"
IsEnabled="False"/>
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
How do I add a bunch of extra menu items on the fly? I've tried:
MenuItem mi = new MenuItem();
mi.Header = "Yeah";
mi.Visibility = System.Windows.Visibility.Visible;
mi.Click += new RoutedEventHandler(mi_Click);
mnuPopup.Items.Add(mi);
but the new menu does actually appear at all. What am I missing?
The Silverlight Context Menu does not support submenus yet. But there are open source alternatives to help you achieve this. Here is one:
www.sl4popupmenu.codeplex.com