Esempio n. 1
0
        /// <summary>
        /// 将MenuModel转为MenuViewItem
        /// </summary>
        private void MenuitemToViewItem()
        {
            var m = new ObservableCollection <NavigationViewItemBase>();

            foreach (var item in _Menus)
            {
                switch (item.menuType)
                {
                case MenuType.Header:
                {
                    var header = new NavigationViewItemHeader()
                    {
                        Content    = item.title,
                        Tag        = item,
                        Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Colors.Gray)
                    };
                    m.Add(header);
                }
                break;

                case MenuType.Menuitem:
                {
                    m.Add(new NavigationViewItem()
                        {
                            Name    = item.name,
                            Content = new Windows.UI.Xaml.Controls.TextBlock()
                            {
                                Text         = item.title,
                                TextTrimming = TextTrimming.WordEllipsis,
                                Margin       = new Thickness(0, 0, 8, 0)
                            },
                            Icon = new Windows.UI.Xaml.Controls.FontIcon()
                            {
                                FontFamily = (Windows.UI.Xaml.Media.FontFamily)Application.Current.Resources["FONTS_MaterialIcons"],
                                Glyph      = item.icon
                            },
                            Tag = item
                        });
                }
                break;

                case MenuType.Separator:
                {
                    m.Add(new NavigationViewItemSeparator());
                }
                break;

                default:
                    break;
                }
            }
            Menus = m;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Menus"));

            MenuUpdated?.Invoke(this, null);
        }
Esempio n. 2
0
        NavigationViewItemHeader CreateNavViewHeaderFromGroup(NavCategoryGroup group)
        {
            var header = new NavigationViewItemHeader();

            header.DataContext = group;

            header.Content = group.Name;
            AutomationProperties.SetName(header, group.AutomationName);
            AutomationProperties.SetHeadingLevel(header, Windows.UI.Xaml.Automation.Peers.AutomationHeadingLevel.Level1);

            return(header);
        }
Esempio n. 3
0
        // reload the contacts bar from scratch using the APPdata
        public async void Load_contacts()
        {
            // reset searchable contacts
            searchable_contacts.Clear();

            // clear the view to start again
            naview.MenuItems.Clear();
            // add the new contatc button back

            NavigationViewItem newcon = new NavigationViewItem();

            newcon.Icon    = new SymbolIcon(Symbol.Add);;
            newcon.Name    = "AddNewContact";
            newcon.Content = "New Contact";
            naview.MenuItems.Add(newcon);

            // Fill up the contacts with files in the localstate folder as per usual
            // create the directory string
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            // Get the first 20 files in the current folder, sorted by name.
            IReadOnlyList <StorageFile> fil = await localFolder.GetFilesAsync(CommonFileQuery.OrderByName, 0, 500);

            string path = localFolder.Path;

            Debug.WriteLine(path);

            foreach (StorageFile file in fil)
            {
                Debug.WriteLine(file.Name + ", " + file.DateCreated);
            }

            char lastKey = ' ';

            // now lets implement the files in the listings
            foreach (StorageFile file in fil)
            {
                // only get the write ones
                if (file.Name.ToString() != "rememberme.txt")
                {
                    // do some checking on adding letter heading stuff
                    // if we have had a change in the first letter
                    char firstkey = ((file.Name.ToString()[0]));
                    if (firstkey != lastKey)
                    {
                        // add a seperator with the letter of the current contact
                        char letter = (file.Name.ToString()[0]);
                        NavigationViewItemHeader head = new NavigationViewItemHeader();
                        head.Content = letter.ToString();;
                        naview.MenuItems.Add(head);

                        lastKey = firstkey;
                    }

                    NavigationViewItem contact = new NavigationViewItem();
                    contact.Name    = file.DisplayName.ToString();
                    contact.Icon    = new SymbolIcon(Symbol.Contact);
                    contact.Content = file.DisplayName.ToString();

                    naview.MenuItems.Add(contact);
                    searchable_contacts.Add(contact.Name.ToString());
                }
            }
        }