Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
365
Bind ContextMenu to columns of grid
posted

Hello,

I want to bind the columns of a grid to a contextmenu so I can change te visibility of the columns by a checkbox. On right click i want the ContextMenu to open and show a list of menuitems with checkboxes for each column. I want to do this in XAML.

I tried the following with no luck:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<

 

 

igMenu:ContextMenuService.Manager

>

 

 

 

<!--Set the attached Manager property to an instance of a ContextMenuManager object-->

 

 

 

<igMenu:ContextMenuManager OpenMode

="RightClick">

 

 

 

<!--Set the ContextMenuManager object's ContextMenu property to an instance of a xamWebContextMenu control-->

 

 

 

<igMenu:ContextMenuManager.ContextMenu

>

 

 

 

<igMenu:XamWebContextMenu ItemsSource="{Binding Source=xRelationGrid, Path

=Columns}">

 

 

 

<igMenu:XamWebContextMenu.ItemTemplate

>

 

 

 

<DataTemplate

>

 

 

 

<Grid

>

 

 

 

<CheckBox IsChecked="{Binding Path=Visibility,

 

 

Converter={StaticResource VisibilityToBool}}" Content="{Binding Path=Key}" />

 

 

 

</Grid>

 

 

 

</DataTemplate

>

 

 

 

</igMenu:XamWebContextMenu.ItemTemplate

>

 

 

 

</igMenu:XamWebContextMenu

>

 

 

 

</igMenu:ContextMenuManager.ContextMenu

>

 

 

 

</igMenu:ContextMenuManager

>

 

 

 

</igMenu:ContextMenuService.Manager

>

Thanx,

Arjan

Parents
No Data
Reply
  • 3071
    posted

    Hi Arjan,
    You can do this in XAML but you need to inherit from XamWebContextMenu:
    public class GridContextMenu : XamWebContextMenu
    {
      public static readonly DependencyProperty TheGridProperty =
        DependencyProperty
    .Register("TheGrid", typeof(XamWebGrid),
       
    typeof(GridContextMenu), new PropertyMetadata(null));
      public XamWebGrid TheGrid
      {
        get{return (XamWebGrid)this.GetValue(GridContextMenu.TheGridProperty);}
        set{this.SetValue(GridContextMenu.TheGridProperty, value);}
      }
      protected override void OnOpening(OpeningEventArgs args)
      {
        this.TheGrid = this.PlacementTargetResolved as XamWebGrid;
        base.OnOpening(args);
      }
    }
    This sample shows how to use the GridContextMenu in XAML:
    <igGrid:XamWebGrid x:Name="TestGrid">
      <igMenu:ContextMenuService.Manager>
        <igMenu:ContextMenuManager>
          <igMenu:ContextMenuManager.ContextMenu>
            <l:GridContextMenu 
              ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=TheGrid.Columns}">
              <l:GridContextMenu.DefaultItemsContainer>
                <DataTemplate>
                  <igMenu:XamWebMenuItem Header="{Binding}" 
                        IsCheckable
    ="True"
                       
    IsChecked="{Binding Path=Visibility, Converter={StaticResource VisibilityConverter}, Mode=TwoWay}">
                  </igMenu:XamWebMenuItem>
                </DataTemplate>
              </l:GridContextMenu.DefaultItemsContainer>
            </l:GridContextMenu>
          </igMenu:ContextMenuManager.ContextMenu>
        </igMenu:ContextMenuManager>
      </igMenu:ContextMenuService.Manager>
    </
    igGrid:XamWebGrid>
    Regards,
    Marin 

Children
No Data