有没有办法访问现有数据库 AppBarButton 当我在除主页之外的特定页面上时,是否以编程方式禁用它?
AppBarButton
<CommandBar Grid.Row="0"> <CommandBar.Content> <Button Style="{StaticResource NavigationBackButtonNormalStyle}" Name="BackButton" VerticalAlignment="Top" Click="Back_Click"/> </CommandBar.Content> <AppBarButton Icon="Mail" Name="ContactUs"/> </CommandBar>
使现代化
主页
public sealed partial class MainPage : Page { public static AppBarButton MyAppBarButton; public MainPage() { this.InitializeComponent(); Current = this; Frame_Main.Navigate(typeof(Frame1)); MyAppBarButton = AppBarButtonSettings; } public static MainPage Current; private void Back_Click(object sender, RoutedEventArgs e) { On_BackRequested(); } private bool On_BackRequested() { if (Frame_Main.CanGoBack) { Frame_Main.GoBack(); return true; } return false; } private void BackInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) { On_BackRequested(); args.Handled = true; } private void AppBarButtonContactUs_Click(object sender, RoutedEventArgs e) { Frame_Main.Navigate(typeof(ContactUs)); } }
联系我们页面
public sealed partial class ContactUs: Page { public ContactUs() { this.InitializeComponent(); } protected override void OnNavigatedTo(NavigationEventArgs e) { MainPage.Current.BackButton.Visibility = Visibility.Visible; MainPage.Current.BackButton.IsEnabled = true; MainPage.MyAppBarButton.IsEnabled = false; } }
当然,从您的代码派生,您可以访问 AppBarButton 名字在代码后面。例如:
private void Btn_Click(object sender, RoutedEventArgs e) { ContactUs.IsEnabled = false; }
你可以制造静电 附件按钮 记录 ContactUs 并使用页面类名访问。
附件按钮
ContactUs
public static AppBarButton MyAppBarButton; public TestPage() { this.InitializeComponent(); MyAppBarButton = ContactUs; }
用法
TestPage.MyAppBarButton.IsEnabled = false;