mvvm ItemDoubleClick command

4 posts, 0 answers
  1. Florin
    Florin avatar
    3 posts
    Member since:
    Jul 2016

    Posted 05 Feb Link to this post

    I have  this user control view.

     

    <UserControl x:Class="TelerikWpfApp1.Views.MainMenuUserControlPanelBarStyle"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:TelerikWpfApp1.Views"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
                 mc:Ignorable="d" 
                 d:DesignHeight="500" d:DesignWidth="250">
        <UserControl.DataContext>
            <Binding Mode="OneWay" Path="MainMenuUserContentPanelBarStyle" Source="{StaticResource Locator}"/>
        </UserControl.DataContext>
        <UserControl.Resources>
            <HierarchicalDataTemplate x:Key="Entity" ItemsSource="{Binding Randuri}">
                <StackPanel Orientation="Horizontal">
                    <Label x:Name="btn" Content="{Binding Titlu}" 
                               Margin="0,0,0,0"
                               />
                </StackPanel>
            </HierarchicalDataTemplate>
        </UserControl.Resources>

        
        <Grid>
                                 <!--ItemDoubleClick  ="{Binding PanelBarItemDoubleClick}"-->

            <telerik:RadPanelBar x:Name="radPanelBar"
                                 Margin="0,0" 
                                 ExpandMode="Multiple" 
                                 ItemsSource="{Binding UserMeniu}"
                                 ItemTemplate="{StaticResource Entity}"  
                                 SelectedItem="{Binding PanelBarSelectedItem, Mode=TwoWay}"
                                 
                                 >
            </telerik:RadPanelBar>

        </Grid>
        
    </UserControl>

     

    And the code for ItemDoubleClick ...:

            private void PanelBarItemDoubleClick(object sender,  Telerik.Windows.RadRoutedEventArgs e) {
                MessageBox.Show("It's working...");
            }

    When I run the project I get the error message "Unable to cast object of type 'System.Reflection.RuntimeEventInfo' to type 'System.Reflection.MethodInfo'."

    What can I do ?

    Thanks.

     

  2. Tanya
    Admin
    Tanya avatar
    577 posts

    Posted 08 Feb Link to this post

    Hello Florin,

    The WPF framework doesn't allow you binding to event handlers using the exposed property. More information on the approaches for attaching handlers to the events is available in this article.

    To attach an event handler from the view model, you can try using the EventToCommandBehavior.

    Hope this helps.

    Regards,
    Tanya
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Florin
    Florin avatar
    3 posts
    Member since:
    Jul 2016

    Posted 08 Feb Link to this post

    Great.

    Thank you.

    I tried, following the example suggested, to use properties of clicked item:

            private void OnCustomCommandExecuted(object obj)  {

                var clickedItem = (obj as RadRoutedEventArgs).OriginalSource as ???; 
                if (clickedItem != null)
                {
                    MessageBox.Show("Clicked Item: " + clickedItem."SomeProperties");
                }
     

    ... but the clickedItem is null every time.

     

     

  4. Tanya
    Admin
    Tanya avatar
    577 posts

    Posted 13 Feb Link to this post

    Hi Florin,

    To pass any parameter in the handler of the command, you should set the command parameter properties. More information about these settings is available in the Command Parameters section.

    Regards,
    Tanya
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top