如何在Metro风格应用中使用SettingsPane和MVVM Light

时间:2012-06-13 15:39:56

标签: windows-8 mvvm-light microsoft-metro

我将MVVM Light Framework用于metro风格的应用程序。

我想在SettingsPane中添加一个命令来显示一个关于页面的内容。 about页面应显示在右侧(如预装的日历应用程序)。对于测试,我在App.xaml.cs中的OnLaunched方法中添加了以下行:

SettingsPane.GetForCurrentView().CommandsRequested += App_CommandsRequested;

并跟随事件处理程序:

void App_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    // Add an About command
    var about = new SettingsCommand("about", "About", (handler) =>
    {
        // show about page in flyout transition...
    });

    args.Request.ApplicationCommands.Add(about);
}

这是唯一的方法吗? 我怎么能飞出那个页面呢?任何提示......?

感谢您的帮助! 迈克尔

2 个答案:

答案 0 :(得分:2)

回答第一个问题:
据我所知,这是做这种事的唯一方法。

回答第二个问题:
要飞出about页面,你可以这样做:

// Add an About command
var about = new SettingsCommand("about", "About", (handler) =>
{
    // show about page in flyout transition...
    var currentPane = new AboutPane(); // the aboutpane is a page
    var myPopup = new Popup();

    myPopup.IsLightDismissEnabled = true;
    myPopup.Width = _settingsWidth;
    myPopup.Height = Window.Current.Bounds.Height;

    myPopup.Width = 346;
    myPopup.Height = Window.Current.Bounds.Height;

    myPopup.Child = currentPane;
    myPopup.SetValue(Canvas.LeftProperty, Window.Current.Bounds.Width - 346);
    myPopup.SetValue(Canvas.TopProperty, 0);
    myPopup.IsOpen = true;
});

args.Request.ApplicationCommands.Add(about);

我希望这能解决你的问题。

答案 1 :(得分:1)

Michael,尝试使用Callisto project on github

中的SettingsFlyout控件

您将需要以下内容:

using Callisto.Controls;

//... other code here

//in your callback for handling the settings command:

// show about page in flyout transition...
var settingsFlyout = new SettingsFlyout();
settingsFlyout.Content = new AboutControl(); //this would be your own user control that contains the about page content

settingsFlyout.IsOpen = true;