0

我正在使用 Visual Studio 2015 并尝试制作汉堡样式导航...但是 splitview 窗格的项目会自动获得边距,并且没有正确堆叠在汉堡按钮下方 [查看附图]。我希望它们正确堆叠在网格最左侧的汉堡按钮下方。我想使用列表框,以便当用户导航到不同的页面时,它仍然被选中/突出显示,所以我无法删除它。我附上了 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>

这是设计器视图的屏幕截图

4

1 回答 1

0

ListBoxItem具有“12,11,12,13”的默认填充(与边距相反)。尝试将PaddingListBoxItems 设置为 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>
于 2017-01-16T00:06:18.140 回答