0
當我將作爲資源對象的應用程序條附加到頁面時,我無法顯示應用程序欄。無法以編程方式加載應用程序條
下面的代碼未能產生一個工作appbar:
的App.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;