MenuItem and updating IsChecked

2 posts, 0 answers
  1. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 11 May 2012 Link to this post

    Hello,
    I'm using RadMenu in an MVVM Caliburn Micro application,I've also a RadDocking that contains my views ... some views are sistem views and they should be enabled/disabled by a menu called Views...I've got difficulties since if I just use the menu (check/unchek) for showing/hiding it work fine, but if I start closing from the "X" I got the IsChecked desinked with the real view state.... since I use this this piece of code for the RadMenu, where do I specify the SubmenuOpened event? If I'm able to access it I can calculate the state of the views...

    <UserControl.Resources>
            <BooleanToVisibilityConverter x:Key="booleanConverter" />
            <selectors:MenuItemTemplateSelector x:Key="templateSelector"></selectors:MenuItemTemplateSelector>
            <HierarchicalDataTemplate x:Key="MenuItemTemplate" ItemsSource="{Binding Items}">
                <TextBlock Text="{Binding Text}" cal:Action.TargetWithoutContext="{Binding}"
                     Visibility="{Binding IsVisible,Mode=TwoWay,Converter={StaticResource booleanConverter}}" />
            </HierarchicalDataTemplate>
     
            
     
     
        </UserControl.Resources>
        <Grid>
            <telerik:RadMenu  x:Name="MenuList" ClickToOpen="False"  BorderBrush="Transparent" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource MenuItemTemplate}"  
                         cal:Message.Attach="[Event ItemClick] = [Action OpenView($eventArgs)]"  >
                <telerik:RadMenu.ItemContainerStyle>
                    <Style TargetType="telerik:RadMenuItem">
                        <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />
                        <Setter Property="IsChecked" Value="{Binding IsChecked, Mode=TwoWay}" />
                        <Setter Property="IsCheckable" Value="{Binding IsCheckable}" />
                        <Setter Property="StaysOpenOnClick" Value="{Binding IsCheckable}" />
                    </Style>
                </telerik:RadMenu.ItemContainerStyle>
     
            </telerik:RadMenu>
        </Grid>
    </UserControl>


    Thanks
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 15 May 2012 Link to this post

    Hi Paolo,

    SubmenuOpened event is a RoutedEvent so could handle it using the AddHandler method. But if you are using ViewModel with two way Binding will be much easier.

    Here is a sample code that shows how to handle SubmenuOpened routed event:
    void MainWindow()
    {
                InitializeComponent();
     
                this.AddHandler(RadMenuItem.SubmenuOpenedEvent, new Telerik.Windows.RadRoutedEventHandler(OnSubmenuOpened));
            }
     
            void OnSubmenuOpened(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                RadMenuItem source = e.OriginalSource as RadMenuItem;
     
                // do something with the MenuItem or its children.
            }
    }


    Regards,
    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top