Interaction logic for FileItem.xaml
Example #1
0
        public void FillView(string location) 
        {
            PrevDir = CurrDir;
            CurrDir = location;
            //clear for next view
            try { FilesView.Items.Clear(); }
            catch { Debug.WriteLine("Unable to clear view"); }
            AddressBar.Text = location;
            var dirinfo = new DirectoryInfo(location);
            var files = dirinfo.GetFiles();
            var dirs = dirinfo.GetDirectories();
            foreach (var file in files)
            {
                var fileName = file.Name;

                var fullName = file.FullName;
                var item = new FileItem
                {
                    Width = 160,
                    Height = 160,
                    Padding = new Thickness(8),
                    Margin = new Thickness(8),
                    Background = System.Windows.Media.Brushes.Transparent,
                    BorderBrush = System.Windows.Media.Brushes.Transparent
                };
                item.MouseDoubleClick += openFile;
                item.MouseRightButtonDown += Item_MouseRightButtonDown;
                item.Click += Item_Click;
                item.FillItem(fullName, fileName);
                FilesView.Items.Add(item);
            }
            foreach (var folder in dirs)
            {
                var folderName = folder.Name;

                var folderFullName = folder.FullName;

                var item = new FileItem
                {
                    Width = 160,
                    Height = 160,
                    Padding = new Thickness(8),
                    Margin = new Thickness(8),
                    Background = System.Windows.Media.Brushes.Transparent,
                    BorderBrush = System.Windows.Media.Brushes.Transparent
                };
                item.MouseRightButtonDown += Item_MouseRightButtonDown;
                item.FillItem(folderFullName, folderName);
                item.MouseDoubleClick += folder_MouseDoubleClick;
                item.Click += Item_Click;
                FilesView.Items.Add(item);

            }
            DataContext = this;
        }
        public void FillView(string location)
        {
            prevDir = currDir;
            currDir = location;
            //clear for next view
            try { FilesView.Items.Clear(); }
            catch { Debug.WriteLine("Unable to clear view"); }
            AddressBar.Text = location;
            DirectoryInfo dirinfo = new DirectoryInfo(location);
            FileInfo[] files = dirinfo.GetFiles();
            DirectoryInfo[] dirs = dirinfo.GetDirectories();
            foreach (FileInfo file in files)
            {
                string FileName = file.Name;

                string FullName = file.FullName;
                if (!FullName.Equals(null))
                {
                    FileItem item = new FileItem();
                    item.Width = 160;
                    item.Height = 160;
                    item.Padding= new Thickness(8);
                    item.Margin = new Thickness(8);
                    item.Background = System.Windows.Media.Brushes.Transparent;
                    item.BorderBrush = System.Windows.Media.Brushes.Transparent;
                    item.MouseDoubleClick += openFile;
                    item.FillItem(FullName, FileName);
                    FilesView.Items.Add(item);
                }

            }
            foreach (DirectoryInfo folder in dirs)
            {
                string FolderName = folder.Name;

                string FolderFullName = folder.FullName;
                if (!FolderFullName.Equals(null))
                {
                    FileItem item = new FileItem();
                    item.Width = 160;
                    item.Height = 160;
                    item.Padding = new Thickness(8);
                    item.Margin = new Thickness(8);
                    item.Background = System.Windows.Media.Brushes.Transparent;
                    item.BorderBrush = System.Windows.Media.Brushes.Transparent;
                    item.FillItem(FolderFullName, FolderName);
                    item.MouseDoubleClick += folder_MouseDoubleClick;

                    FilesView.Items.Add(item);
                }

            }
            this.DataContext = this;
        }