How do i change the size of a checkable menu item?

1 Answer 127 Views
ContextMenu TreeListView
Guilherme
Top achievements
Rank 1
Guilherme asked on 08 Nov 2022, 06:09 PM | edited on 08 Nov 2022, 06:10 PM

I have the following ContexMenu:

Which has the following xaml:

<telerik:RadContextMenu.ContextMenu>
  <telerik:RadContextMenu Opened="RadContextMenu_Opened">
    <telerik:RadMenuItem Header="Add" Command="{Binding AddInstance}" IsEnabled="{Binding EpmModelEditModeEnabled}"
                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}}, Path=UIElement.SelectedItem}"
                    Visibility="{Binding EnableEditMode, Converter={StaticResource boolToVisibilityConverter}}"/>
    <telerik:RadMenuItem Header="Rename (F2)" Click="RenameItemMenu_Click" IsEnabled="{Binding EpmModelEditModeEnabled}"
                      Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}}, Path=UIElement.SelectedItems, Converter={StaticResource canRenameModelVisibilityConverter}}"/>
    <telerik:RadMenuItem Header="Delete" Command="{Binding DeleteObject}" IsEnabled="{Binding EditModeEnabled}"
                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}}, Path=UIElement.SelectedItems}"/>
    <telerik:RadMenuItem Header="Create Chart Analysis" Command="{Binding CreateChart}" 
                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}}, Path=UIElement.SelectedItems}"/>
    <telerik:RadMenuItem Header="Create Dataset Analysis" Command="{Binding CreateDataset}" 
                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}}, Path=UIElement.SelectedItems}"/>
    <telerik:RadMenuItem x:Name="ColumnsMenu" Header="Columns">
      <telerik:RadMenuItem.ItemTemplate>
        <HierarchicalDataTemplate>
          <MenuItem Header="{Binding Header}" IsCheckable="True" IsChecked="{Binding IsVisible, Mode=TwoWay}"/>
        </HierarchicalDataTemplate>
      </telerik:RadMenuItem.ItemTemplate>
    </telerik:RadMenuItem>
  </telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>

I need to know how do i change the size of the internal selection (in blue) to match the size of the external selection (in yellow), because when i click in the external selection the context menu closes.

At least, if it is not possible to change the size of the internal selection, i need that the context menu does not close when the external selection is clicked (adding StaysOpenOnClick="True" in the MenuItem inside of the <HierarchicalDataTemplate> does not work).

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 10 Nov 2022, 03:32 PM

Hello Guilherme,

To achieve your requirement I would recommend you replace the MenuItem in the ItemTemplate with a TextBlock and work with the properties of the parent RadMenuItem that is generated for the template. To do so, you can use the ItemContainerStyle property of the "ColumnsMenu" RadMenuItem. For example:

<telerik:RadMenuItem x:Name="ColumnsMenu" Header="Columns">
	<telerik:RadMenuItem.ItemContainerStyle>
		<Style TargetType="telerik:RadMenuItem">
			<Setter Property="IsCheckable" Value="True" />
			<Setter Property="IsChecked" Value="{Binding IsVisible, Mode=TwoWay}" />
			<Setter Property="StaysOpenOnClick" Value="True" />
		</Style>
	</telerik:RadMenuItem.ItemContainerStyle>
	<telerik:RadMenuItem.ItemTemplate>
		<HierarchicalDataTemplate>
			<TextBlock Text="{Binding Header}"/>
		</HierarchicalDataTemplate>
	</telerik:RadMenuItem.ItemTemplate>
</telerik:RadMenuItem>

I also attached a small sample that shows this approach.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Guilherme
Top achievements
Rank 1
commented on 10 Nov 2022, 05:21 PM

It works great! Thanks!!
Tags
ContextMenu TreeListView
Asked by
Guilherme
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or