This is a migrated thread and some comments may be shown as answers.

MenuItem and updating IsChecked

1 Answer 200 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 11 May 2012, 11:13 AM
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

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 15 May 2012, 08:18 AM
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 >>

Tags
Menu
Asked by
Michele
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Share this question
or