我正在尝试在 WinUI 3.0 中自定义
Content
的 NavigationViewItem
NavigationViewItem
中的按钮不可见?XAML:
<NavigationView x:Name="WorkspacesNavigationView" Grid.Row="1" IsSettingsVisible="False" PaneDisplayMode="LeftMinimal"
IsBackButtonVisible="Collapsed" DataContext="{Binding}" SelectionChanged="WorkspacesNavigationView_SelectionChanged">
<NavigationView.PaneHeader>
<StackPanel Orientation="Horizontal" Margin="8, 0, 0, 0">
<TextBlock Text="Workspaces" VerticalAlignment="Center" />
<Button x:Name="NewWorkspaceButton" Margin="8, 0, 0, 0" Click="NewWorkspaceButton_Click">
<StackPanel Orientation="Horizontal">
<FontIcon Glyph="" Margin="0, 0, 8, 0" FontSize="12"/>
<TextBlock Text="New" FontSize="12"/>
</StackPanel>
</Button>
</StackPanel>
</NavigationView.PaneHeader>
<NavigationView.MenuItems>
<NavigationViewItem>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding WorkspaceName}" />
<Button>
<FontIcon Glyph=""/>
</Button>
<Button>
<FontIcon Glyph=""/>
</Button>
</StackPanel>
</NavigationViewItem>
</NavigationView.MenuItems>
<Frame x:Name="MainFrame" />
</NavigationView>
视图模型:
public class WorkspaceNavigationItem : INotifyPropertyChanged
{
private string _workspaceName;
public string WorkspaceName
{
get => _workspaceName;
set
{
if (_workspaceName != value)
{
_workspaceName = value;
OnPropertyChanged(nameof(WorkspaceName));
}
}
}
public override string ToString()
{
return WorkspaceName;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
您的按钮被隐藏,因为
PaneDisplayMode
设置为 LeftMinimal
。如果您单击菜单按钮、带有 3 条水平线的按钮,或者仅将 PlaneDisplayMode
设置为其他选项,您应该能够看到按钮。
LeftMinimal
: