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

mvvm ItemDoubleClick command

5 Answers 472 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Florin
Top achievements
Rank 2
Florin asked on 05 Feb 2017, 10:09 AM

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.

 

5 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 08 Feb 2017, 03:44 PM
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.
0
Florin
Top achievements
Rank 2
answered on 08 Feb 2017, 10:34 PM

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.

 

 

0
Tanya
Telerik team
answered on 13 Feb 2017, 04:03 PM
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Mohammad
Top achievements
Rank 1
answered on 12 May 2019, 10:06 PM
Hi
When I use this code:
            RadTreeViewItem clickedItem = (obj as RadRoutedEventArgs).OriginalSource as RadTreeViewItem;
clickedItem is null
And when I use this:

            RadTreeView clickedItem = (obj as RadRoutedEventArgs).Source as RadTreeView;
it is not null but I need to access to RadTreeViewItem for LoadOnDeman.
my XAML:
       <telerik:RadTreeView x:Name="radTreeView" Grid.Row="1" Grid.ColumnSpan="3"
                IsTextSearchEnabled="True" telerik:TextSearch.TextPath="Name" Padding="10"
                            IsLoadOnDemandEnabled="True"
                Margin="0 0 1 0" ItemsSource="{Binding Models}">
            <telerik:RadTreeView.ItemTemplate>
                 <HierarchicalDataTemplate ItemsSource="{Binding Items}">
                       <StackPanel Orientation="Horizontal" Margin="2" >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition Width="500"></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <TextBlock Text="{Binding Name}" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" />
                            <TextBlock Text="{Binding TitleTypeName}" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="50 0 0 0"/>
                        </Grid>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </telerik:RadTreeView.ItemTemplate>
                  <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding RaiseOnHandledEvents="True" PassEventArgsToCommand="True" EventName="LoadOnDemand" Command="{Binding OnCustomCommand}" />
                </telerik:EventToCommandBehavior.EventBindings>

and I use MVVM .
Thank you for your helping.
Mahoodi

0
Vladimir Stoyanov
Telerik team
answered on 15 May 2019, 04:11 PM
Hello Mohammad,

Thank you for the provided code. 

I tested the described scenario on my end, however I was not able to reproduce the same result. That is why I am attaching the sample project, which I used for testing purposes. May I ask you to check it out and let me know, if I am missing something? Can you share what modifications are needed so that I can reproduce the same result in the attached project? This way I will check out the behavior on my end and investigate it.

Regards,
Vladimir Stoyanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PanelBar
Asked by
Florin
Top achievements
Rank 2
Answers by
Tanya
Telerik team
Florin
Top achievements
Rank 2
Mohammad
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or