如何使用 C# 从外部按钮单击查看Winrt应用程序中的特定设置页面?
在javascript中我发现这样 WinJS.UI.SettingsFlyout.showSettings("About", "/Settings/About.html")
但我无法在 c# 中找到它,我正在使用callisto设置 Flyouts
如何使用 C# 从外部按钮单击查看Winrt应用程序中的特定设置页面?
在javascript中我发现这样 WinJS.UI.SettingsFlyout.showSettings("About", "/Settings/About.html")
但我无法在 c# 中找到它,我正在使用callisto设置 Flyouts
我也在使用 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)
第一步是在您希望显示设置的页面的 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 的类。
编辑您的 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();
}