This week I was told by a Microsoft Store representative that, "If you want to use a flyout for your settings then use the standard SettingsFlyout which comes from
the right side and has an integrated back button."
Posts in this series:
App Settings Sample
The representative suggested I use the code from the App settings sample found here: http://code.msdn.microsoft.com/windowsapps/App-settings-sample-1f762f49.
The app's description states "This sample demonstrates how to use the ApplicationSettings API and settings flyouts to integrate an app's settings UI with the Settings charm." It was disappointing to discover that (in the C#/XAML version) nothing happens when you select one of the settings commands. Well, nothing except that a text box on the main page displays "You selected the General settings command" or "You selected the Help settings command."
Quickstart: Adding app settings using XAML
In response upon hearing my dismay, the Microsoft Store representative replied: "This is a better example: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh872190.aspx" Well, truth be told, it is a better example: It actually provides some form of flyout functionality. Here are some of my comments (good and bad) about the code:
- The code is for Metro Consumer Preview, not Release Preview, so you have a bunch of brush names to update.
- It nicely shows that flyouts should either be 346 or 646 pixels wide.
- It uses a nice entrance transitions for the flyout.
- The layout is almost identical to the default "Permissions" flyout - which seems to be the gold standard.
- The touch area for the back button is only 30x30 (It should be 50x50 according to http://msdn.microsoft.com/en-us/library/windows/apps/hh465415).
- Rotating the display when the flyout is open causes very interesting (and wrong) behaviors.
- The code does not use a
ContentPresenter for the content of the flyout. This can wrongfully encourage copying/pasting of the same code.
- Since a UserControl cannot override
PopUp, a lot of extra work is required to incorporate this into an application.
- The code-behind for the UserControl
SimpleSettingsNarrow assumes it is encapsulated in a PopUp.
- The amount of code-behind required in MainPage.xaml.cs for displaying the flyout is almost obscene:
- The flyout and a
PopUp are created and the flyout is embedded in the PopUp.
- Two event handlers are wired to watch when the PopUp is closed and the current window is activated.
- The MainPage must close the Popup when it is Activated.
- If you have other reasons to monitor
OnWindowActivated, the code gets even worse.
Do all this for a flyout?
void BlankPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
SettingsCommand cmd = new SettingsCommand("sample", "Sound Options", (x) =>
_settingsPopup = new Popup();
_settingsPopup.Closed += OnPopupClosed;
Window.Current.Activated += OnWindowActivated;
_settingsPopup.IsLightDismissEnabled = true;
_settingsPopup.Width = _settingsWidth;
_settingsPopup.Height = _windowBounds.Height;
SimpleSettingsNarrow mypane = new SimpleSettingsNarrow();
mypane.Width = _settingsWidth;
mypane.Height = _windowBounds.Height;
_settingsPopup.Child = mypane;
_settingsPopup.SetValue(Canvas.LeftProperty, _windowBounds.Width - _settingsWidth);
_settingsPopup.IsOpen = true;
It turns out Tim Heuer has also recently created a solution to the problem: https://github.com/timheuer/callisto. Callisto is a nice attempt at providing those little needed tools for Metro C#/XAML development. However, Callisto too suffers from an inability to handle screen rotations properly. That may be easily fixed. A bit more concerning are the many lines of code-behind required to display the
SettingsFlyout. For example, here is Tim's own code from SettingsSample.xaml.cs to open a single flyout.
Still too much code
private void BlankPage_CommandsRequested(SettingsPane sender,
SettingsCommand cmd = new SettingsCommand("sample", "Sample Custom Setting", (x) =>
SettingsFlyout settings = new SettingsFlyout();
settings.FlyoutWidth = (Callisto.Controls.SettingsFlyout.SettingsFlyoutWidth)
settings.HeaderText = "Foo Bar Custom Settings";
BitmapImage bmp = new BitmapImage(new Uri("ms-appx:///Assets/SmallLogo.png"));
settings.SmallLogoImageSource = bmp;
StackPanel sp = new StackPanel();
ToggleSwitch ts = new ToggleSwitch();
ts.Header = "Download updates automatically";
Button b = new Button();
b.Content = "Test";
settings.Content = sp;
settings.IsOpen = true;
I do have a lot of hope for Tim's library because the
SettingsFlyout was developed as a custom control and the
Generic.xaml appears to be very well written. I think it is only a matter of time before Callisto's
SettingsFlyout takes a nicer shape.
In any case, these discoveries are enough to motivate me to see if I can build a more charming flyout.
Consider reading CharmFlyout - Another Charming Custom Control next.
John Hauck has been developing software professionally since 1981, and focused on Windows-based development since 1988. For the past 17 years John has been working at LECO, a scientific laboratory instrument company, where he manages software development. John also served as the manager of software development at Zenith Data Systems, as the Vice President of software development at TechSmith, as the lead medical records developer at Instrument Makar, as the MSU student who developed the time and attendance system for Dart container, and as the high school kid who wrote the manufacturing control system at Wohlert. John loves the Lord, his wife, their three kids, and sailing on Lake Michigan.