C# 为什么我的SplitView';是否在同一区域中创建内容和窗格?
我整天都在寻找例子,却找不到解决问题的办法。我有一个SplitView,它的窗格中有一个汉堡包菜单,我正在为所选的每个ListBoxItems加载一个框架。但是当我的页面加载时,它看起来像这样(橙色区域是页面背景): 我还想知道如何设置要在启动时加载的任何帧,我曾尝试将TodayListBoxItem设置为IsSelected=“true”和IsEnabled=“true”,但我得到的只是如上所示的相同启动页面,但TodayListBoxItem已被选中。 这是我的XAML:C# 为什么我的SplitView';是否在同一区域中创建内容和窗格?,c#,xaml,uwp,uwp-xaml,C#,Xaml,Uwp,Uwp Xaml,我整天都在寻找例子,却找不到解决问题的办法。我有一个SplitView,它的窗格中有一个汉堡包菜单,我正在为所选的每个ListBoxItems加载一个框架。但是当我的页面加载时,它看起来像这样(橙色区域是页面背景): 我还想知道如何设置要在启动时加载的任何帧,我曾尝试将TodayListBoxItem设置为IsSelected=“true”和IsEnabled=“true”,但我得到的只是如上所示的相同启动页面,但TodayListBoxItem已被选中。 这是我的XAML: <Page
<Page
x:Class="Hamburger.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Hamburger"
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="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<RelativePanel>
<Button Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" FontSize="36" Click="HamburgerButton_Click" />
<TextBlock Name="PageTitle" FontSize="30" Margin="70,0,0,0"></TextBlock>
</RelativePanel>
<SplitView Name="MySplitView"
Grid.Row="1"
DisplayMode="CompactInline"
OpenPaneLength="200"
CompactPaneLength="56"
HorizontalAlignment="Left">
<SplitView.Pane>
<ListBox SelectionMode="Single"
Name="IconsListBox"
SelectionChanged="IconsListBox_SelectionChanged">
<ListBoxItem Name="TodayListBoxItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="36" Text="" />
<TextBlock Text="Today" FontSize="24" Margin="20,0,0,0" />
</StackPanel>
</ListBoxItem>
<ListBoxItem Name="ForecastListBoxItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="36" Text="" />
<TextBlock Text="Forecast" FontSize="24" Margin="20,0,0,0" />
</StackPanel>
</ListBoxItem>
<ListBoxItem Name="SettingsListBoxItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="36" Text="" />
<TextBlock Text="Settings" FontSize="24" Margin="20,0,0,0" />
</StackPanel>
</ListBoxItem>
</ListBox>
</SplitView.Pane>
<SplitView.Content >
<Frame Name="ContentFrame" Background="Tomato" HorizontalAlignment="Stretch" />
</SplitView.Content>
</SplitView>
</Grid>
</Page>
下面是我的xaml.cs:
namespace Hamburger
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void HamburgerButton_Click(object sender, RoutedEventArgs e)
{
MySplitView.IsPaneOpen = !MySplitView.IsPaneOpen;
}
private void IconsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (TodayListBoxItem.IsSelected)
{
PageTitle.Text = "Today";
ContentFrame.Navigate(typeof(TodayPage));
/*
Trying to use a method in TodayPage so that it shows the current
weather
*/
}
else if (ForecastListBoxItem.IsSelected)
{
PageTitle.Text = "Forecast";
ContentFrame.Navigate(typeof(ForecastPage));
}
else if (SettingsListBoxItem.IsSelected)
{
PageTitle.Text = "Settings";
ContentFrame.Navigate(typeof(SettingsPage));
}
}
}
}
namespace汉堡
{
///
///可以单独使用或在框架内导航到的空页。
///
公共密封部分类主页面:第页
{
公共主页()
{
this.InitializeComponent();
}
私有无效汉堡按钮点击(对象发送者,路由目标e)
{
MySplitView.IsPaneOpen=!MySplitView.IsPaneOpen;
}
私有无效IConListBox_SelectionChanged(对象发送者,SelectionChangedEventArgs e)
{
如果(TodayListBoxItem.IsSelected)
{
PageTitle.Text=“今天”;
导航(typeof(TodayPage));
/*
正在尝试在TodayPage中使用方法,以便它显示当前
天气
*/
}
else if(ForecastListBoxItem.IsSelected)
{
PageTitle.Text=“预测”;
导航(typeof(ForecastPage));
}
else if(设置sListBoxItem.IsSelected)
{
PageTitle.Text=“设置”;
导航(typeof(SettingsPage));
}
}
}
}
问题在拆分视图的定义范围内
<SplitView Name="MySplitView"
Grid.Row="1"
DisplayMode="CompactInline"
OpenPaneLength="200"
CompactPaneLength="56"
HorizontalAlignment="Left">
额外好处:如果你想伪造一个selection changed事件,在初始加载时加载一个页面,有几个选项。其中之一是在加载页面后选择项目:
public MainPage()
{
this.InitializeComponent();
this.Loaded += (sender, args) => IconsListBox.SelectedItem = IconsListBox.Items.First();
}
非常感谢你!我回家后会试试这个。我一直在Youtube上观看柯林·布莱克的教程,我想我做的比实际需要做的更多:P
public MainPage()
{
this.InitializeComponent();
this.Loaded += (sender, args) => IconsListBox.SelectedItem = IconsListBox.Items.First();
}