예제 #1
0
        /// <summary>
        /// load directories to listbox
        /// </summary>
        void load_directories()
        {
            _selectedFile      = null;
            _selectedDirectory = null;
            clear_file_preview();

            //get directories list
            directories = DirectoryController.GetDirectories();

            //bind directories to combobox
            cmb_fk_cartella.ItemsSource       = null;
            cmb_fk_cartella.ItemsSource       = directories;
            cmb_fk_cartella.DisplayMemberPath = "name";

            //add special folder
            if (mi_file_no_dir.IsChecked == true)
            {
                directories.Add(new Directory()
                {
                    pk          = -1,
                    name        = "files without directory",
                    description = ""
                });
            }

            //populate listbox with custom stackpanel
            lbxDir.Items.Clear();

            SolidColorBrush lblBrush;
            StackPanel      sp;
            string          header1;
            string          header2;

            foreach (Directory c in directories)
            {
                header1        = c.name;
                header2        = (string.IsNullOrEmpty(c.description)) ? "no description" : c.description;
                sp             = new StackPanel();
                sp.Orientation = Orientation.Vertical;
                lblBrush       = (string.IsNullOrEmpty(c.color))
                    ? Brushes.Black
                    : (SolidColorBrush)(new BrushConverter().ConvertFrom(c.color));
                sp.Children.Add(new Label()
                {
                    Content = header1, FontWeight = FontWeights.Bold, Padding = new Thickness(0), Foreground = lblBrush
                });
                sp.Children.Add(new Label()
                {
                    Content = header2, Padding = new Thickness(0), Margin = new Thickness(0, 0, 0, 3)
                });
                lbxDir.Items.Add(sp);
            }
        }