当我将 appbar 作为资源对象附加到页面时,我无法显示 appbar。
以下代码无法生成有效的应用栏:
应用程序.xaml
<AppBar x:Key="RegisterHome_TopAppBar" >
<AppBar.Content>
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="RegisterHome_MaterialsButton" />
<Button x:Name="RegisterHome_ServicesButton" />
</StackPanel>
</Grid>
</AppBar.Content>
</AppBar>
一些代码隐藏文件
var view = flipView.SelectedItem as Register.Home;
AppBar appbar = Application.Current.Resources["RegisterHome_TopAppBar"] as AppBar;
view.TopAppBar = appbar;
注意:当我使用此代码时,它工作正常:
var appbar = new AppBar();
StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;
Button myButton = new Button();
myButton.Content = "Click Me";
sp.Children.Add(myButton);
appbar.Content = sp;
view.TopAppBar = appbar;