WPF TreeView 이용해 특정 폴더만 보여주기

현재 MVVM 패턴으로 작업을 하고 있는 데

image

요런식으로 (사진 상위 트리에 Food 없는거는 실수입니다)

image

이런 폴더 위치안에서만 값을 뽑아내고 싶은데

하지만 뽑아내면
같은 폴더명만 복사하더라고요…
image

window1.xaml

          <Window.Resources>
    <ObjectDataProvider x:Key="ObjectDataProviderKey">
        <ObjectDataProvider.ObjectInstance>
            <vm:FolderViewModel  FullPath="C:\Food"/>
        </ObjectDataProvider.ObjectInstance>
    </ObjectDataProvider>
    <HierarchicalDataTemplate
        DataType="{x:Type vm:FolderViewModel}"
        ItemsSource="{Binding Path=SubFolderCollection}">
        <TextBlock Text="{Binding Path=Name}" />
    </HierarchicalDataTemplate>


<TreeView Name="folderTreeView" Grid.ColumnSpan="2" Grid.Row="2">
        <TreeViewItem
            Header="Favorit"
            ItemsSource="{Binding Source={StaticResource ObjectDataProviderKey}, Path=SubFolderCollection}" />
    </TreeView>

viewModel-FolderViewModel.cs

  namespace TEST.ViewModels.TreeView
{
    public class FolderViewModel : INotifyPropertyChanging
    {
        namespace TEST.ViewModels.TreeView
        {
        public class FolderViewModel : INotifyPropertyChanging
        {
            #region Field


            private DirectoryInfo directoryInfo;
            private ObservableCollection<FolderViewModel> subFolderCollection;


            private ObservableCollection<FileInfo> fileInfoCollection;

            #endregion


            #region  - FullPath


            public string FullPath
            {
                get
                {
                    return directoryInfo.FullName;
                }

                set
                {
                    if (Directory.Exists(value))
                    {
                        directoryInfo = new DirectoryInfo(value);
                    }
                    else
                    {
                        throw new ArgumentException("No exist.", "FullPath");
                    }
                }
            }

            #endregion
            #region  - Name


            private string _Name = string.Empty;

            public event PropertyChangingEventHandler PropertyChanging;

            public string Name
            {
                get
                {
                    _Name = directoryInfo.Name;
                    return _Name;
                }

                set
                {
                    _Name = value;
                    OnpropertyChanaged("Name");
                }
            }

            private void OnpropertyChanaged(string v)
            {
                throw new NotImplementedException();
            }



            #endregion
            #region  - SubFolderCollection


            public ObservableCollection<FolderViewModel> SubFolderCollection
            {
                get
                {
                    if (subFolderCollection == null)
                    {
                        subFolderCollection = new ObservableCollection<FolderViewModel>();

                        DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories();

                        //DirectoryInfo[] directoryInfoArray = (DirectoryInfo[])this.directoryInfo.GetFileSystemInfos();
                        for (int i = 0; i < directoryInfoArray.Length; i++)
                        {
                            FolderViewModel folder = new FolderViewModel();
                            FullPath = directoryInfoArray[i].FullName;

                            this.subFolderCollection.Add(folder);
                        }
                    }

                    return subFolderCollection;
                }
            } 
            #endregion
            #region  FileInfoCollection


            public ObservableCollection<FileInfo> FileInfoCollection
            {
                get
                {
                    if (this.fileInfoCollection == null)
                    {
                        this.fileInfoCollection = new ObservableCollection<FileInfo>();

                        FileInfo[] fileInfoArray = this.directoryInfo.GetFiles();

                        for (int i = 0; i < fileInfoArray.Length; i++)
                        {
                            this.fileInfoCollection.Add(fileInfoArray[i]);
                        }
                    }

                    return this.fileInfoCollection;
                }
            }

            #endregion

            #region  - Folder()

            public FolderViewModel()
            {
                FullPath = @"C:\Food\";
            }

            #endregion
        }
    }

여기 코드인데 뭐가 틀린지 모르겠네요 ㅠㅠ

좋아요 1

해결했습니다…!
var folder = new FolderViewModel(directoryInfoArray[i].FullName);

로 변경하니 되네용

좋아요 4