0

In my project I use list view and want to get the object from double click event, I mean when user click on listview row, then from viewmodel I want to get the clicked object.

XAML:

cal:Message.Attach="[Event MouseDoubleClick] = [Action RowDoubleClick($dataContext)]"

ViewModel

public void RowDoubleClick(object pm)
{
}

but in object pm in ViewModel I get all off the listview object, I need a single object.

Can anyone help me regarding this issue.

XAML

<ListView AlternationCount="2" HorizontalAlignment="Center" cal:Message.Attach="[Event MouseDoubleClick] = [Action RowDoubleClick($dataContext)]"
                              Name="lvProcessList"  SelectionChanged="lvProcessList_SelectionChanged" 
                              ScrollViewer.VerticalScrollBarVisibility="Visible"  ScrollViewer.HorizontalScrollBarVisibility="Visible"  ScrollViewer.CanContentScroll="True" 
                              VerticalAlignment="Top" Width="779" Grid.ColumnSpan="8"  IsSynchronizedWithCurrentItem="True" Height="391" >
                        <ListView.ItemContainerStyle>
                            <Style  TargetType="{x:Type ListViewItem}" >
                                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                                <Setter Property="HorizontalAlignment" Value="Center"/>
                                <Setter Property="BorderBrush" Value="Black" />
                                <Setter Property="BorderThickness" Value="0,0,1,1" />
                                <Setter Property="Height" Value="30" />
                                <Setter Property="IsSelected" Value="{Binding chkWspSelect}"/>
                                <Style.Triggers>
                                    <Trigger Property="ItemsControl.AlternationIndex"  Value="0">
                                        <Setter Property="Background" Value="LightBlue" />
                                    </Trigger>
                                    <Trigger Property="ItemsControl.AlternationIndex"  Value="1">
                                        <Setter Property="Background" Value="LightGray" />
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="Background" Value="SteelBlue"/>
                                    </Trigger>
                                </Style.Triggers>
                                <!--<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />-->
                            </Style>
                        </ListView.ItemContainerStyle>
                        <ListView.View>
                            <GridView>
                                <GridView.Columns>
                                    <GridViewColumn>
                                        <DataGrid AutoGenerateColumns="True" CanUserAddRows="False">
                                            <DataGrid.Columns>
                                                <DataGridTemplateColumn >
                                                    <DataGridTemplateColumn.HeaderTemplate>
                                                        <DataTemplate>
                                                            <CheckBox Name="chkWspSelectAll" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="chkWspSelectAll_Checked"  Unchecked="chkWspSelectAll_Unchecked"  IsThreeState="False"/>
                                                        </DataTemplate>
                                                    </DataGridTemplateColumn.HeaderTemplate>
                                                </DataGridTemplateColumn>
                                            </DataGrid.Columns>
                                        </DataGrid>
                                        <GridViewColumn.CellTemplate >
                                            <DataTemplate>
                                                <CheckBox Name="chkWspSelect"  HorizontalContentAlignment="Center"  HorizontalAlignment="Center" VerticalAlignment="Center" Checked="chkWspSelect_Checked"  Unchecked="chkWspSelect_Unchecked"  IsThreeState="False"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="200" Header="Process name">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock  FontWeight="Bold" Text="{Binding ProcessName}" TextAlignment="Center"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="120" Header="Ongoing">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Ongoing}" TextAlignment="Center"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="110" Header="Un-Strated">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Un-Strated}" TextAlignment="Center"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="110" Header="Completed">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Completed}" TextAlignment="Center"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="200" Header="Action" >
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <WrapPanel >
                                                    <Button  Width="50" Height="25" Margin="30,0,0,0" x:Name="btnDelete" Click="BtnDelete_Click">
                                                        <StackPanel Orientation="Horizontal" >
                                                            <Image Source="/Pipe_Flushing;component/Image/Trash.png"  Height="20"/>
                                                        </StackPanel>
                                                    </Button>
                                                    <Button x:Name="btnHistory" Width="50" Height="25" Margin="10,0,0,0" Click="BtnHistory_Click">
                                                        <StackPanel>
                                                            <Image Source="/Pipe_Flushing;component/Image/History.png"  Height="20"/>
                                                        </StackPanel>
                                                    </Button>
                                                    <Button x:Name="btnHistory1" Width="50" Height="25" Margin="10,0,0,0" Content="test" cal:Message.Attach="[Event Click] = [Action Edit($dataContext)]">
                                                    </Button>
                                                </WrapPanel>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                </GridView.Columns>
                            </GridView>
                        </ListView.View>
                    </ListView>
  • Can you share your xaml code? `$dataContext` means the DataContext of the element, where message is attached. It seems, that you've attached the message to the entire list view, instead of list view item – Pavel Anikhouski Dec 28 '19 at 10:13
  • Yea I think so, Let me check – Rafiqul Hasan Dec 28 '19 at 10:17
  • @PavelAnikhouski Can you help me? in which location I need to attach the message ? – Rafiqul Hasan Jan 02 '20 at 04:55
  • Somewhere in datatemplate of list view item. You can also use binding for selected item, as it shown in this [thread](https://stackoverflow.com/questions/9487084/getting-row-information-after-a-doubleclick) – Pavel Anikhouski Jan 02 '20 at 08:18

0 Answers0