0

Hello I have a model called FileDirectoryModel and it contains:

   public class FileDirectoryModel
    {
        public string imgPath { get; set; }
        public string DirPath { get; set; }
        public string FileName { get; set; }
        public string size { get; set; }
        public string FileType { get; set; }
        public DateTime Modifed { get; set; }
        public string FullName { get; set; }
    }

I also have a ListView :

   <ListView x:Name="lstExplorer"
              Background="White"
              ItemsSource="{Binding DirectoryCollection}"
              SelectedItem="{Binding SelectedModel}"
              >
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseDoubleClick">
                <i:InvokeCommandAction Command="{Binding FileExplorerClickCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Name"
                                Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding imgPath}"
                                       Height="20"
                                       Width="20"
                                       Stretch="Fill"/>
                                <TextBlock x:Name="explorerText"
                                         Text="{Binding FileName}">
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Width="50">
                    <GridViewColumnHeader>
                        <TextBlock Text="Size" />                            
                    </GridViewColumnHeader>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Text="{Binding size}" />
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Width="100">
                    <GridViewColumnHeader>
                        <TextBlock Text="Type" />
                    </GridViewColumnHeader>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Text="{Binding FileType}" />
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Width="100">
                    <GridViewColumnHeader>
                        <TextBlock Text="Modifed" />
                    </GridViewColumnHeader>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Text="{Binding Modifed}" />
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

            </GridView>
        </ListView.View>
    </ListView>

and DirectoryCollection is :

    private ObservableCollection<FileDirectoryModel> _DirectoryCollection;

    public ObservableCollection<FileDirectoryModel> DirectoryCollection
    {
        get { return _DirectoryCollection; }
        set
        {
            if (_DirectoryCollection != value)
            {
                _DirectoryCollection = value;
                OnPropertyChanged();
            }
        }
    }

There is a dubbleclick command that will open the file that is selected but I'm having a hard time trying yo figure out how to allow someone to change the name of the selected item.

Please note that I saw File ListView, Change name which doesn't apply because they are telling how to change the file name not how to have xaml allow the change.

Community
  • 1
  • 1
JamTay317
  • 1,017
  • 3
  • 18
  • 37

1 Answers1

0

You will need to setup a CommandParameter to pass get the name of the double clicked item.

<i:EventTrigger EventName="MouseDoubleClick">
    <i:InvokeCommandAction Command="{Binding FileExplorerClickCommand}"
     CommandParameter="{Binding}/>
</i:EventTrigger>

The FileDirectoryModel item that was double clicked will get passed to the FileExplorerClickCommand method (you will need to change the method params. You can then perform whatever you need on that item.

AndrewJE
  • 858
  • 2
  • 9
  • 19