Skip to content

Instantly share code, notes, and snippets.

@kw0006667
Created December 4, 2012 16:00
Show Gist options
  • Save kw0006667/4205494 to your computer and use it in GitHub Desktop.
Save kw0006667/4205494 to your computer and use it in GitHub Desktop.
在主畫面,將原來的「首頁」改成「詳細設定」,並建立舉呼叫剛才自訂的子畫面
public MainPage()
{
this.InitializeComponent();
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
}
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand urlCommand = new SettingsCommand("urlCommand", "詳細設定", onSettingsCommand);
args.Request.ApplicationCommands.Add(urlCommand);
SettingsCommand urlCommand_2 = new SettingsCommand("urlCommand_2", "Bing", onSettingsCommand);
args.Request.ApplicationCommands.Add(urlCommand_2);
}
void onSettingsCommand(IUICommand command)
{
switch (command.Label)
{
case "詳細設定":
Setting();
break;
case "Bing":
urlCommandLink2_Clicked();
break;
default:
break;
}
}
Popup settingPopup;
void Setting()
{
settingPopup = new Popup();
settingPopup.Closed += settingPopup_Closed;
settingPopup.IsLightDismissEnabled = true;
Window.Current.Activated += Current_Activated;
settingPopup.Width = 346;
settingPopup.Height = Window.Current.Bounds.Height;
SettingPage pane = new SettingPage();
pane.Width = 346;
pane.Height = Window.Current.Bounds.Height;
settingPopup.Child = pane;
settingPopup.SetValue(Canvas.LeftProperty, SettingsPane.Edge == SettingsEdgeLocation.Right ? (Window.Current.Bounds.Width - 346) : 0);
settingPopup.SetValue(Canvas.TopProperty, 0);
settingPopup.IsOpen = true;
}
void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
this.settingPopup.IsOpen = false;
}
void settingPopup_Closed(object sender, object e)
{
Window.Current.Activated -= Current_Activated;
}
async void urlCommandLink2_Clicked()
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("http://bing.com"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment