NavigationViewItem.MenuItemsSource Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur sumber objek yang digunakan untuk menghasilkan anak dari NavigationViewItem.
public:
property Platform::Object ^ MenuItemsSource { Platform::Object ^ get(); void set(Platform::Object ^ value); };
/// [get: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)]
/// [set: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)]
IInspectable MenuItemsSource();
void MenuItemsSource(IInspectable value);
/// [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)]
/// [get: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)]
/// [set: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)]
IInspectable MenuItemsSource();
void MenuItemsSource(IInspectable value);
public object MenuItemsSource { [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)] get; [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)] set; }
[Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)]
public object MenuItemsSource { [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)] get; [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallback(enable=true)] set; }
var object = navigationViewItem.menuItemsSource;
navigationViewItem.menuItemsSource = object;
Public Property MenuItemsSource As Object
<NavigationViewItem MenuItemsSource="{x:Bind Object}" .../>
Nilai Properti
Sumber objek yang menampung turunan dari NavigationViewItem.
- Atribut
-
Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallbackAttribute
Contoh
Contoh ini menambahkan hierarki dengan menentukan templat item menjadi NavigationViewMenuItem, dengan Kontennya diatur menjadi label item menu, dan properti MenuItemsSource terikat ke tingkat hierarki berikutnya.
<DataTemplate x:Key="NavigationViewMenuItem" x:DataType="local:Category">
<muxc:NavigationViewItem Content="{x:Bind Name}" MenuItemsSource="{x:Bind Children}"/>
</DataTemplate>
<muxc:NavigationView x:Name="navview"
MenuItemsSource="{x:Bind categories, Mode=OneWay}"
MenuItemTemplate="{StaticResource NavigationViewMenuItem}"
ItemInvoked="{x:Bind OnItemInvoked}"
Expanding="OnItemExpanding"
Collapsed="OnItemCollapsed"
PaneDisplayMode="Left">
<StackPanel Margin="10,10,0,0">
<TextBlock Margin="0,10,0,0" x:Name="ExpandingItemLabel" Text="Last Expanding: N/A"/>
<TextBlock x:Name="CollapsedItemLabel" Text="Last Collapsed: N/A"/>
</StackPanel>
</muxc:NavigationView>
public class Category
{
public String Name { get; set; }
public String Icon { get; set; }
public ObservableCollection<Category> Children { get; set; }
}
public sealed partial class HierarchicalNavigationViewDataBinding : Page
{
public HierarchicalNavigationViewDataBinding()
{
this.InitializeComponent();
}
public ObservableCollection<Category> Categories = new ObservableCollection<Category>()
{
new Category(){
Name = "Menu Item 1",
Icon = "Icon",
Children = new ObservableCollection<Category>() {
new Category(){
Name = "Menu Item 2",
Icon = "Icon",
Children = new ObservableCollection<Category>() {
new Category() {
Name = "Menu Item 2",
Icon = "Icon",
Children = new ObservableCollection<Category>() {
new Category() { Name = "Menu Item 3", Icon = "Icon" },
new Category() { Name = "Menu Item 4", Icon = "Icon" }
}
}
}
}
}
},
new Category(){
Name = "Menu Item 5",
Icon = "Icon",
Children = new ObservableCollection<Category>() {
new Category(){
Name = "Menu Item 6",
Icon = "Icon",
Children = new ObservableCollection<Category>() {
new Category() { Name = "Menu Item 7", Icon = "Icon" },
new Category() { Name = "Menu Item 8", Icon = "Icon" }
}
}
}
},
new Category(){ Name = "Menu Item 9", Icon = "Icon" }
};
private void OnItemInvoked(object sender, NavigationViewItemInvokedEventArgs e)
{
var clickedItem = e.InvokedItem;
var clickedItemContainer = e.InvokedItemContainer;
}
private void OnItemExpanding(object sender, NavigationViewItemExpandingEventArgs e)
{
var nvib = e.ExpandingItemContainer;
var name = "Last Expanding: " + nvib.Content.ToString();
ExpandingItemLabel.Text = name;
}
private void OnItemCollapsed(object sender, NavigationViewItemCollapsedEventArgs e)
{
var nvib = e.CollapsedItemContainer;
var name = "Last Collapsed: " + nvib.Content;
CollapsedItemLabel.Text = name;
}
}
public sealed class NavigationViewItemExpandingEventArgs
{
public NavigationViewItemExpandingEventArgs() {}
public object ExpandingItem { get; }
public NavigationViewItemBase ExpandedItemContainer { get; }
public bool IsSettingsInvoked { get; }
public NavigationTransitionInfo RecommendedNavigationTransitionInfo { get; }
}
public sealed class NavigationViewItemCollapsedEventArgs
{
public NavigationViewItemCollapsedEventArgs() {}
public object CollapsedItem { get; }
public NavigationViewItemBase CollapsedItemContainer { get; }
public bool IsSettingsInvoked { get; }
public NavigationTransitionInfo RecommendedNavigationTransitionInfo { get; }
}
Berlaku untuk
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk