Prism 7 Library with WPF to get the folder and files of my drive

Nitesh Giri 1 Reputation point
2022-03-13T20:19:43.967+00:00

I am using Prism 7 Library with WPF to get the folder and files of my drive.

  1. I am getting an error at Set Property of DirectoryList: An exception of type "System.StackOverflowException" was thrown.
  2. My Back button is not working, I am getting errors at data conversion type.

Here is my Code:

public class FilePath
    {
        public string  FileName { get; set; }

        public string inputFilePath { get; set; }

    }


public class OpenDataViewModel : BindableBase
    {

        public OpenDataViewModel()
        {
            ListDrives();            
        }

        private string _title = "Browsing Window";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        private FilePath _selecteddirectory;
        public FilePath SelectedDirectory
        {
            get { return _selecteddirectory; }
            set
            {
                SetProperty(ref _selecteddirectory, value);
                ListDirectoryContent(_selecteddirectory);
            }
        }

        public List<FilePath> _directoryList;
        public List<FilePath> DirectoryList
        {
            get { return _directoryList; }
            set { SetProperty(ref _directoryList, value); }
        }



        private List<FilePath> _fileList;
        public List<FilePath> FileList
        {
            get { return _fileList; }
            set { SetProperty(ref _fileList, value); }
        }

        public void ListDrives()
        {


            DirectoryList = new List<FilePath>();


            foreach (var drive in Directory.GetLogicalDrives())
            {
                DirectoryList.Add(new FilePath()
                {

                    FileName = drive.Remove(1, drive.LastIndexOf('\\') ) ,

                    inputFilePath = Convert.ToString(drive)
                }); 
            }

        }

        public void ListDirectoryContent(FilePath inputPath)
        {


                DirectoryList = new List<FilePath>();


            foreach (var directory in Directory.GetDirectories(inputPath.inputFilePath))
            {
                DirectoryList.Add(new FilePath()
                {

                    FileName = directory.Remove(0,3),

                    inputFilePath = Convert.ToString(directory)
                });

            }



            FileList = new List<FilePath>();


            foreach (var fileData in Directory.GetFiles(inputPath.inputFilePath))
            {
                FileList.Add(new FilePath()
                {

                    FileName = fileData.Remove(0, 3),

                    inputFilePath = Convert.ToString(fileData)
                }) ;

            }

        }

private DelegateCommand _goBackCommand;
public DelegateCommand GoBackCommand =>
_goBackCommand ?? (_goBackCommand = new DelegateCommand(ExecuteGoBackCommand));

void ExecuteGoBackCommand()
{                             
   SelectedDirectory = Path.GetFullPath(Path.Combine(SelectedDirectory.inputFilePath, ".."));
}

And this how my xmal looks:

<ListView ItemsSource="{Binding DirectoryList}" Grid.Row="2" Grid.Column="0" Background="Aqua" SelectedValue="{Binding SelectedDirectory}" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding FileName}" Header="Folder" Width="250" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListView ItemsSource="{Binding FileList}" Grid.Row="2" Grid.Column="1" Background="Brown" SelectedValue="{Binding SelectedFile}" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding FileName}" Header="Files" Width="275" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ListBox>-->
<Button x:Name="BackButton" Command="{Binding GoBackCommand}" Content="Back" Grid.Column="1" Grid.Row="0" Background="Pink" FontSize="10">
</Button>

Developer technologies | XAML
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.