Cannot open ContextMenu from inside DataGrid CellEditing Template?

2 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 06 Oct 2010 Link to this post

    I am having a problem trying to open a ContextMenu inside a DataGrid...

    The following code works properly when it exists other places in my application.
    <ToggleButton Grid.Column="1" Content="Click Me!" Height="20" Width="100" IsChecked="{Binding IsOpen, ElementName=rcm, Mode=TwoWay}" >
      <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu x:Name="rcm" Placement="Bottom">
          <telerik:RadMenuItem Header="Item1" />
          <telerik:RadMenuItem Header="Item2" />
          <telerik:RadMenuItem Header="Item3" />
        </telerik:RadContextMenu>
      </telerik:RadContextMenu.ContextMenu>
    </ToggleButton>

    However if I place this code inside a DataGrid (specifically a CellEditingTemplate of a DataGridTemplateColumn, it does not work - i.e: the menu never opens.
    <sdk:DataGrid RowHeight="100" AutoGenerateColumns="False" ItemsSource="{Binding Collection}" >
      <sdk:DataGrid.Columns>
        <sdk:DataGridTemplateColumn>
          <sdk:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
              <TextBlock Foreground="Red" Text="{Binding Property1}" />
            </DataTemplate>
          </sdk:DataGridTemplateColumn.CellTemplate>
          <sdk:DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="1*" />
                  <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>
                <TextBox Foreground="Red" Text="{Binding Property1, Mode=TwoWay}" />
                <ToggleButton Grid.Column="1" Content="Button" Height="20" Width="100" IsChecked="{Binding IsOpen, ElementName=rcm, Mode=TwoWay}" >
                  <telerik:RadContextMenu.ContextMenu>
                    <telerik:RadContextMenu x:Name="rcm" Placement="Bottom" >
                      <telerik:RadMenuItem Header="Item1" />
                      <telerik:RadMenuItem Header="Item2" />
                      <telerik:RadMenuItem Header="Item3" />
                    </telerik:RadContextMenu>
                  </telerik:RadContextMenu.ContextMenu>
                </ToggleButton>
              </Grid>
            </DataTemplate>
          </sdk:DataGridTemplateColumn.CellEditingTemplate>
        </sdk:DataGridTemplateColumn>
      </sdk:DataGrid.Columns>
    </sdk:DataGrid>

    asdasd
    asdasd
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 10 Oct 2010 Link to this post

    Hello Rob,

    This looks like problem in the DataGrid control. When RadContextMenu opens it will take focus so that keyboard navigation works but this cause DataGrid to think that edited row lost focus and will return the cells to cell template which will cause RadContextMenu to unload and close.

    I will let you know if I find a workaround for this case.

    Kind regards,
    Hristo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top