Search Results

Search found 200 results on 8 pages for 'contextmenu'.

Page 1/8 | 1 2 3 4 5 6 7 8  | Next Page >

  • Binding a TreeView with ContextMenu in Xaml

    - by Michael Stoll
    I'm pretty new to Xaml and need some advise. A TreeView should be bound to a hierarchical object structure. The TreeView should have a context menu, which is specific for each object type. I've tried the following: <TreeView> <TreeView.Resources> <DataTemplate x:Key="RoomTemplate"> <TreeViewItem Header="{Binding Name}"> <TreeViewItem.ContextMenu> <ContextMenu> <MenuItem Header="Open" /> <MenuItem Header="Remove" /> </ContextMenu> </TreeViewItem.ContextMenu> </TreeViewItem> </DataTemplate> </TreeView.Resources> <TreeViewItem Header="{Binding Name}" Name="tviRoot" IsExpanded="True" > <TreeViewItem Header="Rooms" ItemsSource="{Binding Rooms}" ItemTemplate="{StaticResource RoomTemplate}"> <TreeViewItem.ContextMenu> <ContextMenu> <MenuItem Header="Add room"></MenuItem> </ContextMenu> </TreeViewItem.ContextMenu> </TreeViewItem> </TreeViewItem> But with this markup the behavior is as intended, but the child items (the rooms) are indented too much. Anyway all the bining samples I could find use TextBlock instead of TreeViewItem in the DataTemplate, but wonder how to integrate the ContextMenu there.

    Read the article

  • XAML ContextMenu gets bound to wrong row in a DataGrid

    - by Simon_Weaver
    I have a XAML based ContextMenu bound to the rows in a datagrid. It works just fine - until the grid is scrolled! This is the context menu for one of the controls in the visual tree or a DataGrid row. <data:DataGridTemplateColumn Header="Customer Details" Width="*"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid Background="Transparent"> <!-- allows click in entire cell --> <controlsInputToolkit:ContextMenuService.ContextMenu> <controlsInputToolkit:ContextMenu> <controlsInputToolkit:MenuItem Header="{Binding CompletedOrderId,StringFormat='Create Reminder for order #\{0\}'}" CommandParameter="{Binding}"> <controlsInputToolkit:MenuItem.Command> <command:CreateReminderCommand/> </controlsInputToolkit:MenuItem.Command> <controlsInputToolkit:MenuItem.Icon> <Viewbox> <Image Width="19" Height="18" Source="../images/reminders.png" VerticalAlignment="Center"/> </Viewbox> </controlsInputToolkit:MenuItem.Icon> </controlsInputToolkit:MenuItem> <controlsInputToolkit:ContextMenu> <controlsInputToolkit:ContextMenuService.ContextMenu> ...... The ICommand is CreateReminderCommand and the CommandParameter is bound to the data item for the row itself. This works just fine - I can right click on a row and it will show me the correct text in the menu item 'Create Reminder for order 12345'. Then I scroll the datagrid down a page. If I keep right clicking on items then suddenly I'll see the wrong order number for a row. I think what must be happening is this : The DataGrid is reusing instances of MenuItem that it has previously created. How can I force a refresh of the ContextMenu when it is displayed for an item that changes? There's no 'Update method on the ContextMenu or ContextMenuService.

    Read the article

  • WPF ContextMenu bind some property to another property of the same control

    - by bebicasoft
    I have a ContextMenu and a ColumnHeaderStyle defined in Window.Resource section witch i use-it to a DataGrid ColumnHeader. My code is something like this: <ContextMenu x:Key="cm_columnHeaderMenu"/> <Style x:Key="DefaultColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="ContextMenu" Value="{StaticResource cm_columnHeaderMenu}" /> </Style> <DataGrid Grid.Column="2" Grid.Row="1" x:Name="dgridFiles" IsReadOnly="True" ColumnHeaderStyle="{StaticResource DefaultColumnHeaderStyle}"> I want to know if I can (and if the answer it true, then HOW I could do it) bind the ContextMenu Visibility property to same control ContextMenu Items.Count>0 property. Initially based on some other treeView control selections made there shoud be no items in the context menu, but i wish to add dinamically items in ContextMenu based on selection in treeView. This part is done, the context has those items. On some selections there are no-items, but still on the grid it appears an empty ContextMenu. So I believe the easiest part it would be to bind the Visibility to Items.Count property of the same control. Sorry if my english is not good enought, I'll try to explain better if i didnt make clear 1st time.

    Read the article

  • Setting a WPF ContextMenu's PlacementTarget property in XAML?

    - by qntmfred
    <Button Name="btnFoo" Content="Foo" > <Button.ContextMenu Placement="Bottom" PlacementTarget="btnFoo"> <MenuItem Header="Bar" /> </Button.ContextMenu> </Button> gives me a runtime error 'UIElement' type does not have a public TypeConverter class I also tried <Button Name="btnFoo" Content="Foo" > <Button.ContextMenu Placement="Bottom" PlacementTarget="{Binding ElementName=btnFoo}"> <MenuItem Header="Bar" /> </Button.ContextMenu> </Button> and that put the ContextMenu in the top left corner of my screen, rather than at the Button

    Read the article

  • Defining a ContextMenu in a DataGridRow style

    - by Brent
    I'm trying to clean up some of my xaml in my views by moving a lot of the DataGrid styles into a ResourceDictionary. One of the things I'd like to move is the ContextMenu that is bound to some commands in the ViewModel. However, when I move the context menu to the ResourceDictionary, the commands are are never firing anymore, and I can't figure out why. I've defined the ContextMenu in the DataGridRow style so that when the user right clicks on the columnheader, no ContextMenu is shown... it will only be shown they right click on a row. Am I doing something wrong here? FYI I'm using VS 2010 RTM if that makes a difference. <Style x:Key="DataGridRowStyle" TargetType="{x:Type DataGridRow}"> <Setter Property="Height" Value="20"/> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="New" Command="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext.NewCommand}"> <MenuItem.Icon> <Image Source="/Images/DocumentWhite(32N).png" Width="16" Height="16"/> </MenuItem.Icon> </MenuItem> <MenuItem Header="Open" Command="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext.OpenCommand}"> <MenuItem.Icon> <Image Source="/Images/FolderOpenYellow(32N).png" Width="16" Height="16"/> </MenuItem.Icon> </MenuItem> <MenuItem Header="Delete" Command="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext.DeleteCommand}"> <MenuItem.Icon> <Image Source="/Images/Delete(32N).png" Width="16" Height="16"/> </MenuItem.Icon> </MenuItem> </ContextMenu> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="{StaticResource hoverGradient}"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{StaticResource BtnOverFill}"/> </Trigger> </Style.Triggers> </Style>

    Read the article

  • WPF: How to make Contextmenu select and forget?

    - by Kave
    I have a Contextmenu with a ListBox inside. Whenever I right click my control and select a value from my contextmenu the last selected value stays marked and I can't select that value again. The idea is, that I may select the same value within the COntextmenu in order to turn a property on or off. Should be quite basic, what am I missing? Many Thanks,

    Read the article

  • WPF ContextMenu with bound items: Items.Count == 0 in ContextMenuOpening event

    - by OregonGhost
    I have a ContextMenu with the ItemsSource bound to the selected item of a list view, like this: <ContextMenu ItemsSource="{Binding Path=PlacementTarget.SelectedItem, RelativeSource={RelativeSource Self}, Converter={StaticResource possibleConverter}}"/> The possibleConverter enumerates all possible values for a property of the the selected item, which are shown in the context menu. In the Opened event of the context menu, I select the current value like this: var cm = e.OriginalSource as ContextMenu; if (cm != null) { var lv = cm.PlacementTarget as ListView; var field = lv.SelectedItem as Field; var item = cm.ItemContainerGenerator.ContainerFromItem(cm.Items.OfType<object>().Where(o => o.ToString().Equals(field.StringValue)).FirstOrDefault()) as MenuItem; if (item != null) { item.IsChecked = true; } } Not particularly elegant, but it works. With the debugger I verified that the ContextMenu.Items.Count property has a non-zero value when expected (i.e. cm.Items.Count is non-zero in the if). So far, so good. There are, however, items in the listview where the context menu will have no items. In this case, an empty menu is shown. I tried to suppress this in the ContextMenuOpening event in the list view, like this: var lv = sender as ListView; if (lv != null) { var cm = lv.ContextMenu; if ((cm != null) && (cm.Items.Count > 0)) { // Here we want to check the current item, which is currently done in the Opened event. } else { e.Handled = true; } } Seems like it should work. However, cm.Items.Count is always zero. This is true even if ListView.SelectedItem did not change: For an item with menu entries, the menu is shown correctly after the first click, so the data binding has already happend. It is shown correct the second time as well, but in any case, Items.Count is zero in the ContextMenuOpening event. What am I missing? How can I suppress empty context menus? Why is the count zero in the ContextMenuOpening handler, which is in Windows Forms (ContextMenuStrip.Opening) the canonical point where to do these things? EDIT: Upon further investigating, it turns out that in the ContextMenuOpening handler, any binding to the listview fails, which is why ItemsSource is null. I tried to bind via ElementName, via a FindAncestor relationship, all to no avail. The PlacementTarget is null during that event. An ugly hack worked though: In the ContextMenuOpening event, I assign the list view to the ContextMenu.Tag property, while the ItemsSource binding now binds to Tag.SelectedItem. This updates the binding, so Items.Count is what it should be. It's still strange. How can you do meaningful things in ContextMenuOpening other than replacing the menu or something, if the binding fails because somehow the context menu is out of context during the event? Was it only tested with static pre-defined menu items?

    Read the article

  • WPF Treeview contextmenu IsChecked binding MVVM

    - by BrettRobi
    I've got a TreeView to which I associate a ContextMenu. That contextmenu has an item whose IsChecked property I want to bind to my ViewModel. Since I am using a tree each treeitem is bound to a subproperty of my ViewModel. In the VS2010 output window I am seeing this databinding error: BindingExpression path error: 'IsAutoStart' property not found on 'object' ''HostMgmtViewModel' (HashCode=12565727)'. BindingExpression:Path=IsAutoStart; DataItem='HostMgmtViewModel' This clearly shows it is trying to bind to my ViewModel and not to the treeitem's associated data. How do I bind to the correct object? Remember my contextmenu is associated with the whole TreeView not to the specific treeitem.

    Read the article

  • identifying id of listitem for contextmenu

    - by martinjd
    I have a View that extends Activity. A ListView will display a number of listitems. When the user long clicks I would like to present them with a contextmenu allowing them to select edit, delete etc... and then identify the listitem that was selected as the item to perform the action on. In onCreate I have: listView.setAdapter(adapter); listView.setOnItemClickListener(onListClick); listView.setOnItemLongClickListener(onListLongClick); registerForContextMenu(listView); I have a method onCreateContextMenu @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle("Context Menu"); menu.add(0, v.getId(), 0, "Edit"); menu.add(0, v.getId(), 0, "Delete"); } and also onContextItemSelected @Override public boolean onContextItemSelected(MenuItem item) { if (item.getTitle() == "Edit") { // edit action } else if (item.getTitle() == "Delete") { // delete action } else { return false; } return true; } I am not sure where to go from here to get the correct row/listitem.

    Read the article

  • dynamic ContextMenu in TreeView vs. MVVM

    - by bitbonk
    I have a tree of ViewModels displayed as a TreeView (using HierarchicalDataTemplate). Each ViewModel instance has different commands that can be executed on it wich again are exposed as a list of command ViewModels for each item ViewModel. How can I create a single ContextMenu that opens at the TreeViewItem that was rightclicked and that populates its commands from the underlying item ViewModel's command ViewModels list? All in a decent MVVM fashion ...

    Read the article

  • Configuring jstree right-click contextmenu for different node types

    - by MGOwen
    I've seen an example somewhere online showing how to customise the appearance of jstree's right-click context menu (using contextmenu plugin). For example, allow my users to delete "documents" but not "folders" (by hiding the "delete" option from the context menu for folders). Now I can't find that example. Can anyone point me in the right direction? The official documentation didn't really help.

    Read the article

  • Android 2.1 fling gesture captured on textview but still a contextmenu opens

    - by hermo
    The following problem seems unique to 2.1, happens both on an emulator and on a nexus. The same example works fine on other platforms I've tested (1.5, 1.6 and 2.0 emulators). I've added created gestureListener as described in this post. The difference is that I've added the listener on a TextView which also has a contextMenu registered, i.e. sth like the following: onCreate(...) { ... // Layout contains a large TextView on which I want to add a context menu tv = findViewById(R.id.text_view); tv.registerForContextMenu(this); // create the gestureListener according above mentioned post. gestureListener = ... // set the listener on the text-view tv.setOnTouchListener(gestureListener); ... } When testing it, the correct gesture is recognized alright, but every other time it also causes the context menu to be opened. As the same example is working on non 2.1 platforms, I've got a feeling it is not my code that is the problem... Thankful for any suggestions.

    Read the article

  • ContextMenu not popping up on Long click

    - by primal
    Hi, The context menu is not popping up on the long click on the list items in the list view. I've extended the base adapter and used a view holder to implement the custom list with textviews and an imagebutton. adapter = new MyClickableListAdapter(this, R.layout.timeline, mObjectList); list.setAdapter(adapter); registerForContextMenu(list); Implementation of onCreateContextMenu @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub super.onCreateContextMenu(menu, v, menuInfo); Log.d(TAG, "Entering Context Menu"); menu.setHeaderTitle("Context Menu"); menu.add(Menu.NONE, DELETE_ID, Menu.NONE, "Delete") .setIcon(R.drawable.icon); } The XML for listview is here <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> I've been trying this for many days. I think its impossible to register Context-menu for a custom list view like this. Correct me if I am wrong (possibly with sample code). Now I am thinking of a adding a button to the list item and it displays a menu on clicking it. Is it possible with some other way than using Dialogs? Any help would be much appreciated..

    Read the article

  • Android: Registering ContextMenu for a Custom ListAdapter

    - by primal
    Hi, I made a custom list adapter extending the Base adapter. Each item in the list has an imagebutton, 2 textviews and a button. I tried to add the context menu to the list so as to display some options for an item in the list. registerForContextMenu(getListView()); I used a MenuInflater object to inflate the context menu xml file. But on clicking the items in the list nothing shows up or the usual highlighting of the item of list on click isn't shown. Is it that the context menu doesn't work for custom list views? Any help would be much appreciated. Regards, Primal

    Read the article

  • Javascript ContextMenu on a TD

    - by Dave
    If I attach a context menu to a td, it fires okay for text in the TD, but if I add a div to the TD, the context menu will not fire when right clicking on the div. How can I make the context menu fire when anything, data or divs, are right clicked in the td?

    Read the article

  • CF - How to get mouse position when ContextMenu pops up ??

    - by no9
    I have a problem i cannot solve. In my view (that shows a map) i created a contextMenu. When context menu is invoked i need to get the position where the user has clicked on the map. Here is my problem: In the view i already have onMouseDown event that gets me the coordinates where the user clicked. private void MapView_MouseDown(object sender, MouseEventArgs e) { this.lastMouseDownX = e.X; this.lastMouseDownY = e.Y; } When the contextMenu is invoked i need the same data, but the problem is that contextMenu only has EventArgs that dont keep the data i need. Furthermore ... contextMenu is invoked when user presses and holds mouse for a second and when its invoked the code does not enter onMouseDown event ! It just goes into popup event on my context menu.... I tried putting this in my popup event, but the coordinates are not ok. Y coordinate is way off the chart. private void servicesContextMenu_Popup(object sender, EventArgs e) { this.lastMouseUpX = Control.MousePosition.X; this.lastMouseUpX = Control.MousePosition.Y; } I also tried this, but with no success ... the problem remains ... when contextMenu is invoked the code does not fire onMouseDown event. http://www.mofeel.net/58-microsoft-public-dotnet-framework-compactframework/19285.aspx Help?

    Read the article

  • Workarounds for supporting MVVM in the Silverlight ContextMenu service

    - by cibrax
    As I discussed in my last post, some of the Silverlight controls does not support MVVM quite well out of the box without specific customizations. The Context Menu is another control that requires customizations for enabling data binding on the menu options. There are a few things that you might want to expose as view model for a menu item, such as the Text, the associated icon or the command that needs to be executed. That view model should look like this, public class MenuItemModel { public string Name { get; set; } public ICommand Command { get; set; } public Image Icon { get; set; } public object CommandParameter { get; set; } } This is how you can modify the built-in control to support data binding on the model above, public class CustomContextMenu : ContextMenu { protected override DependencyObject GetContainerForItemOverride() { CustomMenuItem item = new CustomMenuItem(); Binding commandBinding = new Binding("Command"); item.SetBinding(CustomMenuItem.CommandProperty, commandBinding);   Binding commandParameter = new Binding("CommandParameter"); item.SetBinding(CustomMenuItem.CommandParameterProperty, commandParameter);   return item; } }   public class CustomMenuItem : MenuItem { protected override DependencyObject GetContainerForItemOverride() { CustomMenuItem item = new CustomMenuItem();   Binding commandBinding = new Binding("Command"); item.SetBinding(CustomMenuItem.CommandProperty, commandBinding);   return item; } } The change is very similar to the one I made in the TreeView for manually data binding some of the Menu item properties to the model. Once you applied that change in the control, you can define it in your XAML like this. <toolkit:ContextMenuService.ContextMenu> <e:CustomContextMenu ItemsSource="{Binding MenuItems}"> <e:CustomContextMenu.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" > <ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" /> <TextBlock Margin="0" Text="{Binding Name, Mode=OneWay}" FontSize="12"/> </StackPanel> </DataTemplate> </e:CustomContextMenu.ItemTemplate> </e:CustomContextMenu> </toolkit:ContextMenuService.ContextMenu> The property MenuItems associated to the “ItemsSource” in the parent model just returns a list of supported options (menu items) in the context menu. this.menuItems = new MenuItemModel[] { new MenuItemModel { Name = "My Command", Command = new RelayCommand(OnCommandClick), Icon = ImageLoader.GetIcon("command.png") } }; The only problem I found so far with this approach is that the context menu service does not support a HierarchicalDataTemplate in case you want to have an hierarchy in the context menu (MenuItem –> Sub menu items), but I guess we can live without that.

    Read the article

  • WPF - Redrawing a Context Menu when Items change?

    - by Rachel
    I have a ItemsControl in a ScrollViewer, and when the items exceed the width of the ScrollViewer they are put into a ContextMenu and shown as a DropDown instead. My problem is that when the Context Menu is first loaded, it saves the saves the size of the Menu and does not redraw when more commands get added/removed. For example, a panel has 3 commands. 1 is visible and 2 are in the Menu. Viewing the menu shows the 2 commands and draws the control, but then if you resize the panel so 2 are visible and only 1 command is in the menu, it doesn't redraw the menu to eliminate that second menu item. Or even worse, if you shrink the panel so that no commands are shown and all 3 are in the Menu, it will only show the top 2. Here's my code: <Button Click="DropDownMenu_Click" ContextMenuOpening="DropDownMenu_ContextMenuOpening"> <Button.ContextMenu> <ContextMenu ItemsSource="{Binding Path=MenuCommands}" Placement="Bottom"> <ContextMenu.Resources> <Style TargetType="{x:Type MenuItem}"> <Setter Property="Command" Value="{Binding Path=Command}" /> <Setter Property="Visibility" Value="{Binding Path=IsVisible, Converter={StaticResource ReverseBooleanToVisibilityConverter}}"/> </Style> </ContextMenu.Resources> <ContextMenu.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=DisplayName}" /> </DataTemplate> </ContextMenu.ItemTemplate> </ContextMenu> </Button.ContextMenu> </Button> Code Behind: void DropDownMenu_ContextMenuOpening(object sender, ContextMenuEventArgs e) { Button b = sender as Button; b.ContextMenu.IsOpen = false; e.Handled = true; } private void DropDownMenu_Click(object sender, RoutedEventArgs e) { Button b = sender as Button; ContextMenu cMenu = b.ContextMenu; if (cMenu != null) { cMenu.PlacementTarget = b; cMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; } } I have tried using InvalidateVisual and passing an empty delegate on Render to try and force a redraw, however neither works. I'm using .Net 4.0.

    Read the article

  • Context Menu on QGraphicsWidget

    - by onurozcelik
    Hi, In my application I have two object type. One is field item, other is composite item. Composite items may contain two or more field items. Here is my composite item implementation. #include "compositeitem.h" CompositeItem::CompositeItem(QString id,QList<FieldItem *> _children) { children = _children; } CompositeItem::~CompositeItem() { } QRectF CompositeItem::boundingRect() const { //Not carefully thinked about it return QRectF(QPointF(-50,-150),QSizeF(250,250)); } void CompositeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { FieldItem *child; foreach(child,children) { child->paint(painter,option,widget); } } QSizeF CompositeItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { QSizeF itsSize(0,0); FieldItem *child; foreach(child,children) { // if its size empty set first child size to itsSize if(itsSize.isEmpty()) itsSize = child->sizeHint(Qt::PreferredSize); else { QSizeF childSize = child->sizeHint(Qt::PreferredSize); if(itsSize.width() < childSize.width()) itsSize.setWidth(childSize.width()); itsSize.setHeight(itsSize.height() + childSize.height()); } } return itsSize; } void CompositeItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { qDebug()<<"Test"; } My first question is how I can propagate context menu event to specific child. Picture on the above demonstrates one of my possible composite item. If you look on the code above you will see that I print "Test" when context menu event occurs. When I right click on the line symbol I see that "Test" message is printed. But when I right click on the signal symbol "Test" is not printed and I want it to be printed. My second question what cause this behaviour. How do I overcome this.

    Read the article

  • How to add Silverlight 4 ContextMenu to DataGrid row or column?

    - by Simon_Weaver
    Silverlight 4 has a new ContextMenu control in the latest toolkit. I can't find ANY examples anywhere on how to reliably use this ContextMenu on a DataGrid. Theres a tonne of context menus out there but I want to use the new version from the toolkit. I'd like to be able to set context menus for rows and cells. Everything I've tries ends up being bound to the wrong item in the grid after scrolling.

    Read the article

1 2 3 4 5 6 7 8  | Next Page >