views:

69

answers:

0

Hi guys:

I have this View:

<Grid Margin="10,0,10,10">
<StackPanel>
    <wpftoolkit:Accordion 
    Margin="4" 
    HorizontalAlignment="Stretch" 
    Name="accordionCB"
    ItemsSource="{Binding Path=ContentBlockCategories}"
    SelectionMode="ZeroOrMore">
        <wpftoolkit:Accordion.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Stretch" Margin="0 0 0 4">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                            Text="{Binding Description}"
                            Grid.Column="0" VerticalAlignment="Center" />
                </Grid>
            </DataTemplate>
        </wpftoolkit:Accordion.ItemTemplate>
        <wpftoolkit:Accordion.ContentTemplate>
            <DataTemplate>

                <!--Not Raise MouseDoubleClick Command-->

                <ListView 
                x:Name="lvContentBlocks"
                AlternationCount="2" 
                ItemsSource="{Binding ContentBlocks}"
                IsSynchronizedWithCurrentItem="True"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseDoubleClick">
                            <cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding Path=MouseDoubleClick}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0,0,0,5">
                                <StackPanel VerticalAlignment="Top">
                                    <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </DataTemplate>
        </wpftoolkit:Accordion.ContentTemplate>
    </wpftoolkit:Accordion>

    <!--Raise MouseDoubleClick Command-->

    <ListView 
                x:Name="lvContentBlocks"
                AlternationCount="2" 
                ItemsSource="{Binding ContentBlockCategories}"
                IsSynchronizedWithCurrentItem="True"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseDoubleClick">
                <cmd:EventToCommand Command="{Binding MouseDoubleClick}" PassEventArgsToCommand="True" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Margin="0,0,0,5">
                    <StackPanel VerticalAlignment="Top">
                        <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackPanel>
</Grid>

And this ViewModel:

public class MainViewModel : ViewModelBase
    {
        public ObservableCollection<ContentBlockCategory> ContentBlockCategories
        {
            get
            {
                return new ObservableCollection<ContentBlockCategory>
                    {
                        new ContentBlockCategory{
                            Id = 1,
                            Description = "Category 1",
                            ContentBlocks = new Collection<ContentBlock>
                            {
                                new ContentBlock{
                                    Id = 1,
                                    Description = "Content Block 1",
                                    Text = "Text"
                                }
                            }
                        }
                    };
            }
            set
            {
                RaisePropertyChanged("ContentBlockCategories");
            }
        }

        public RelayCommand<MouseButtonEventArgs> MouseDoubleClick
        {
            get;
            private set;
        }

        public MainViewModel()
        {
            MouseDoubleClick = new RelayCommand<MouseButtonEventArgs>(e =>
            {
                DependencyObject dep = (DependencyObject)e.OriginalSource;

                while ((dep != null) && !(dep is ListViewItem))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }

                if (dep == null) return;

                ContentBlockCategory contentBlockSelected = (ContentBlockCategory)((ListViewItem)dep).DataContext;
            });
        }
    }

The first ListView inside an Accordion not raise the RelayCommand in the ViewModel but the second ListView raise the RelayCommand without any problem.

What's the problem?

Regards