Creating tabs in WinRT

前端 未结 4 822
南方客
南方客 2021-02-01 20:04

I\'m working on a C#/XAML Metro style app for Windows 8. The XAML in WinRT does not have a \"tab\" control. However, I\'m trying to emulate the way a result in the Windows 8 sto

4条回答
  •  旧巷少年郎
    2021-02-01 21:07

    Styling a ListBox is preferable to styling a radio button group.

    The following code uses a ListBox with a horizontal stack panel to create the tab item header. A ContentControl displays the tab content as a user control.

    I've only tested this with WPF, but hopefully it will work on WinRT.

    enter image description here

    
        
        
    
    
        
            
        
        
            
            
        
    
        
            
                
                    
                
            
            
                
                    
                
            
        
    
        
    
    

    View model

    public class MyTabViewModel : INotifyPropertyChanged
    {
        public MyTabViewModel()
        {
            Items =
                new List
                    {
                        new MyTabItem
                            {
                                Title = "Overview",
                                Content = new UserControl1()
                            },
                        new MyTabItem
                            {
                                Title = "Detail",
                                Content = new UserControl2()
                            },
                        new MyTabItem
                            {
                                Title = "Reviews",
                                Content = new UserControl3()
                            },
                    };
        }
    
        public IEnumerable Items { get; private set; }
    
        private MyTabItem _selectedItem;
    
        public MyTabItem SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                _selectedItem = value;
                PropertyChanged(this, new PropertyChangedEventArgs("SelectedItem"));
            }
        }
    
        #region Implementation of INotifyPropertyChanged
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        #endregion
    }
    
    public class MyTabItem
    {
        public string Title { get; set; }
        public UserControl Content { get; set; }
    }
    

提交回复
热议问题