一般来说,我对编码真的很陌生,我正在努力了解 XAML/UWP/C#。
我正在尝试在 Visual Studio 中制作一个应用程序,并且我正在尝试正确使用 SplitView/SplitView.Content 中的 Frame 来加载其他页面,以便从我的导航中单击按钮。我已经在网格中构建了我的页面,无论我做什么,我拥有的框架都完全偏离中心并且加载页面偏离中心
我对此真的很陌生,并希望能提供任何帮助,但请原谅我的天真 - 我真的很新,而且是自学成才的,所以我有很多东西要学。
我尝试使用网格以及垂直和水平对齐来使框架居中,但我一点运气都没有。
<Grid>
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False" CompactPaneLength="50" OpenPaneLength="250">
<!--#region Navigation-->
<SplitView.Pane>
<StackPanel Background="#2A2939" Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="15" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="15" />
</Grid.RowDefinitions>
<!-- Navigation -->
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="NavigationButton" Height="50" Background="Transparent" Click="Navigation_Click">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navburger-white.png" Width="22" Height="22" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Margin="0,0,0,5" Text="Navigation" Foreground="#FFF" FontFamily="Segoe UI" FontSize="22" FontWeight="Normal" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center">
<Line Opacity="0.3" Stroke="#FFF" X1="300" Y1="0" X2="0" Y2="0" StrokeThickness="1"/>
</StackPanel>
<!-- Home -->
<StackPanel Grid.Column="0" Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="HomeButton" Click="HomeButton_Click" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navhome-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Home" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Medical -->
<StackPanel Grid.Column="0" Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="MedicalButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navmedical-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Medical" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Dental -->
<StackPanel Grid.Column="0" Grid.Row="4" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="DentalButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navdental-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Dental" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Mental & Occupational -->
<StackPanel Grid.Column="0" Grid.Row="5" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="MentalAndOccupationalButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navmental-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Mental & Occupational" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Rehabilitation -->
<StackPanel Grid.Column="0" Grid.Row="6" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="RehabilitationButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navrehab-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Rehabilitation" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Radiology -->
<StackPanel Grid.Column="0" Grid.Row="7" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="RadiologyButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navradiation-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Radiology" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Practice Management -->
<StackPanel Grid.Column="0" Grid.Row="8" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="PracticeManagementButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navpractice-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Practice Management" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<!-- Medicines Management -->
<StackPanel Grid.Column="0" Grid.Row="9" Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="MedicinesManagementButton" Height="50" Background="Transparent">
<Grid Width="250">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Column="0" Grid.Row="0" Source="ms-appx:///Assets/Icons/navmedicine-grey.png" Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Medicines Management" Foreground="#ADB2BF" FontFamily="Segoe UI" FontSize="18" FontWeight="Light" Typography.Capitals="AllSmallCaps" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" TextWrapping="WrapWholeWords"/>
</Grid>
</Button>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="10" Orientation="Horizontal" VerticalAlignment="Center">
<Line Opacity="0.3" Stroke="#FFF" X1="300" Y1="0" X2="0" Y2="0" StrokeThickness="1"/>
</StackPanel>
</Grid>
</StackPanel>
</SplitView.Pane>
<!--#endregion-->
<!--#region Main Panel-->
<SplitView.Content>
<Frame x:Name="MainPage_Frame" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center">
</Frame>
</SplitView.Content>
<!--#endregion-->
</SplitView>
</Grid>
抱歉上面的代码转储,但我真的不知道我哪里出错了
在第二个区域 - 主面板 - 我无法让框架 (x:Name="MainPage_Frame") 集中在单击导航中的按钮时应该加载的页面(第一个区域 - 导航) .
单击按钮在加载我的其他测试页面时可以正常工作,但如前所述,问题是页面加载完全偏离了我期望框架所在的位置。
在此先感谢您的帮助!