如何使用C#从外部按钮点击查看 winrt 应用程序中的特定设置页面?
在javascript中,我发现像 WinJS.UI.SettingsFlyout.showSettings(“关于”,“/设置/关闭”)
但是我无法在c#中找到这个,我使用 callisto 来设置弹出窗口
答案 0 :(得分:7)
我也在使用Callisto和C#,这就是我解决问题的方法。
void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
var settings = new SettingsCommand("settings", "Settings", new UICommandInvokedHandler(showSettings));
args.Request.ApplicationCommands.Add(settings);
var credits = new SettingsCommand("credits", "Credits", new UICommandInvokedHandler(showCredits));
args.Request.ApplicationCommands.Add(credits);
}
public void showSettings(IUICommand command)
{
var settings = new SettingsFlyout();
settings.Content = new SettingsUserControl();
settings.HeaderBrush = new SolidColorBrush(_background);
settings.Background = new SolidColorBrush(_background);
settings.HeaderText = "Settings";
settings.IsOpen = true;
}
public void showCredits(IUICommand command)
{
var settings = new SettingsFlyout();
settings.Content = new CreditsUserControl();
settings.HeaderBrush = new SolidColorBrush(_background);
settings.Background = new SolidColorBrush(_background);
settings.HeaderText = "Credits";
settings.IsOpen = true;
}
然后从其他页面我可以致电
((App)Application.Current).showCredits(null);
或
((App)Application.Current).showSettings(null);
打开我想看的设置窗格:o)
答案 1 :(得分:1)
第一步是在SettingsPane上为要显示设置的页面添加CommandsRequest事件的侦听器。例如:
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
然后定义事件处理程序
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand generalCommand = new SettingsCommand("GeneralSettings", ResourceLoader.GetString("GeneralText"), (x) =>
{
SettingsFlyout settings = new SettingsFlyout();
settings.HeaderBrush = Resources["SettingsHeaderBrush"] as SolidColorBrush;
settings.HeaderText = ResourceLoader.GetString("GeneralText");
settings.Background = new SolidColorBrush(Windows.UI.Colors.White);
settings.Content = new GeneralSettingsFlyout();
settings.IsOpen = true;
settings.Height = Window.Current.Bounds.Height;
// Optionally, add a closed event handler
settings.Closed += settings_Closed;
});
}
请注意,在这种情况下,GeneralSettingsFlyout只是一个页面,一旦选择了特定的设置,它就会被加载到设置窗格中(Callisto会自动处理)。
SettingsFlyout是来自Callisto的类。
答案 2 :(得分:0)
修改您的app.xaml文件,并参考以下代码段:
App::OnLaunched()
{
.
.
var rootFrame = new CharmFrame { CharmContent = new CharmFlyouts() };
SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
.
.
}
然后,当您想要显示该设置时,请执行以下操作:
SomeOtherMethod()
{
((Window.Current.Content as CharmFrame).CharmContent as CharmFlyouts).ShowSettings();
}