最後我想出的解決方案,這要歸功於Windows 8.1中Appsetting示例應用程序。首先的settingsFlyout XAML頁面添加到您的project.I添加隱私彈出代碼在我的應用程序的主頁上這樣
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested -= onCommandsRequested;
}
void onCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs e)
{
SettingsCommand defaultsCommand = new SettingsCommand("Privacy", "Privacy",
(handler) =>
{
Privacy sf = new Privacy();
sf.Show();
});
e.Request.ApplicationCommands.Add(defaultsCommand);
}
然後在我的Privacy.xaml頁面添加以下代碼
public Privacy()
{
this.InitializeComponent();
this.Loaded += (sender, e) =>
{
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += SettingsFlyout1_AcceleratorKeyActivated;
};
this.Unloaded += (sender, e) =>
{
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated -= SettingsFlyout1_AcceleratorKeyActivated;
};
}
void SettingsFlyout1_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
{
// Only investigate further when Left is pressed
if (args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown &&
args.VirtualKey == VirtualKey.Left)
{
var coreWindow = Window.Current.CoreWindow;
var downState = CoreVirtualKeyStates.Down;
bool menuKey = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
bool shiftKey = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;
if (menuKey && !controlKey && !shiftKey)
{
args.Handled = true;
this.Hide();
}
}
}
感謝大家的幫助!如果有人遇到困難,只需打我;)
這很容易,用代碼替換此代碼(開放URL),這將打開設置魅力的另一頁。 – crea7or
我認爲你正在尋找Flyout,看看[Flyout示例](http://code.msdn.microsoft.com/windowsapps/Flyout-sample-258757b3)。 – kiewic
@ crea7or我們假設我有一個名爲「Privacy.xaml」的XAML頁面,它有一個超鏈接。現在我想在設置的魅力中顯示這個頁面。我將如何調用這個頁面?並且我已經在App.xaml.cs頁面 – KhanXc