拆分视图项目未正确堆叠在汉堡包按钮下方

The splitview items aren't properly stacking beneath hamburger button

我正在研究 Visual Studio 2015 并尝试制作汉堡包样式的导航...但是 splitview 窗格的项目自动获得边距,并且没有正确堆叠在汉堡包按钮下方[看附图]。我希望它们正确地堆叠在网格最左侧的 Hamburger 按钮下方。 我想使用列表框,这样当用户导航到另一个页面时,它仍然是 selected/highlighted,所以我无法删除它。 我已经附上了 MainPage.xaml 代码和我使用过的样式的代码。希望你能帮忙..谢谢!

<Page
x:Class="MathAssistant.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MathAssistant"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Button Name="HBbutton" Click="HBbutton_Click" Grid.Column="0" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontFamily="Segoe MDL2 Assets" Content="&#xE700;"  FontSize="25" Background="BlueViolet"/>

    <TextBlock Name="Heading" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Center"  FontSize="36" Foreground="CornflowerBlue" />

    <SplitView Grid.Row="1" 
               Grid.ColumnSpan="2"
               Name="Menu"
               DisplayMode="CompactOverlay" 
               OpenPaneLength="270" 
               CompactPaneLength="56">
        <SplitView.Pane>
            <ListBox SelectionMode="Single" 
                     SelectionChanged="MenuListBox_SelectionChanged">
                <ListBoxItem Name="MenuItemUnitConverter">
                    <StackPanel Orientation="Horizontal">
                        <Image Margin="0" Source="Assets/unitconverterlogo.png" Style="{StaticResource SplitviewLogoStyle}" />
                        <TextBlock FontSize="24" Margin="20,0,0,0">
                            <Run Text="Unit Converter"/>
                        </TextBlock>
                    </StackPanel>
                </ListBoxItem>
                <ListBoxItem Name="MenuItemCalculator" >
                    <StackPanel Orientation="Horizontal">
                        <Image Margin="0" Source="Assets/calculatorlogo.png" Style="{StaticResource SplitviewLogoStyle}"/>
                        <TextBlock FontSize="24" Margin="20,0,0,0">Calculator</TextBlock>
                    </StackPanel>
                </ListBoxItem>
            </ListBox>
        </SplitView.Pane>
        <SplitView.Content>
            <Frame Name="MyFrame" Grid.Column="1" Grid.Row="1"></Frame>
        </SplitView.Content>
    </SplitView>

</Grid>

<Application.Resources>
    <Style TargetType="Image" x:Key="SplitviewLogoStyle">
        <Setter Property="Height" Value="50" />
        <Setter Property="Width" Value="45" />
    </Style>

ListBoxItem 的默认填充(与边距相反)为“12,11,12,13”。尝试将 ListBoxItems 的 Padding 设置为 0 然后它应该向左对齐。要将它设置在中心,您可以这样做:

<ListBoxItem Name="MenuItemUnitConverter" Padding="0">
    <StackPanel Orientation="Horizontal">
        <Image Margin="4" Source="Assets/unitconverterlogo.png" Style="{StaticResource SplitviewLogoStyle}" />
        <TextBlock FontSize="24" Margin="20,0,0,0">
            <Run Text="Unit Converter"/>
        </TextBlock>
    </StackPanel>
</ListBoxItem>

并修改样式,使图像的左边距 + 宽度 + 图像的右边距 = SplitView.Width (4+48+4=56):

<Style TargetType="Image" x:Key="SplitviewLogoStyle">
    <Setter Property="Height" Value="50" />
    <Setter Property="Width" Value="48" />
</Style>