Windows 8 Store Apps Learning (37) Contract: Settings Contract

Source: Internet
Author: User
Tags xmlns

Introduced

Re-imagine the contract for Windows 8 Store Apps

Settings Contract-The right sidebar is called a Charm, where the "setting" is called a settings Contract

Example

Demo Application of Settings Contract

Contracts/settingscontract/demo.xaml

<page
    x:class= "XamlDemo.Contracts.SettingsContract.Demo"
    xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "
    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:d=" http:// schemas.microsoft.com/expression/blend/2008 "
    xmlns:mc=" http://schemas.openxmlformats.org/ markup-compatibility/2006 "
    mc:ignorable=" D ">
    
    <grid background=" Transparent ">
        < StackPanel margin= "0 0 0" > <button name= "btnaddsettings" content= "
    
            Register Settingspane event" C lick= "Btnaddsettings_click_1"/> <button name= "btnshowsettings" Open content= "Settingspane"
    
            Btnshowsettings_click_1 "margin=" 0 0 0 "/> <textblock name=" lblmsg "fontsize=" 14.667 "textwrapping="
    
            Wrap "margin=" 0 0 0 "/>
                
        </StackPanel>
    </Grid>
</Page>
Contracts/settingscontract/demo.xaml.cs
* * Settings Contract-the right sidebar is called the Charm, where the "setting" is called the settings Contract * * Settingspane-Setup Panel * Getforcurrentview ( -Get the current Settingspane * Show ()-Turn on Settingspane * commandsrequested-events that are triggered each time the Settingspane is opened (two types are Settings  Pane and Settingspanecommandsrequestedeventargs parameters) * * Uicommandinvokedhandler-The callback function of the event that is raised when the setting item in the Setup Panel is clicked, is a delegate (a type that is Iuicommand parameters, Settingscommand implements this interface) * * Settingscommand-Settings Panel set item * ID-set item ID, identify with * Label-set item name, explicit     Invoked-Specifies the event parameter in the handler * settingspanecommandsrequestedeventargs-commandsrequested event of the event that is raised after a stand-alone setting item * 
 Request-Returns the settingspanecommandsrequest type of data * * Settingspanecommandsrequest-Contains the available attributes in the Commandsrequested event
* Applicationcommands-settingscommand Set * * using System;
Using Windows.UI.ApplicationSettings;
Using Windows.UI.Popups;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Controls.Primitives; Using Windows.UI.Xaml.Media.AnimatiOn
    
Using Windows.UI.Xaml.Navigation; Namespace XamlDemo.Contracts.SettingsContract {public sealed partial class Demo:page {//Bounce-defined Detail Settings page,
        Used pop-up box private popup _settingspopup = new popup ();
    
        Whether to register the Settingspane commandsrequested event private bool _commandsrequestedregistered = false; Public Demo () {this.
        InitializeComponent (); } protected override void Onnavigatedfrom (NavigationEventArgs e) {base.
    
            Onnavigatedfrom (e); Leave this page to remove commandsrequested listener if (this._commandsrequestedregistered) {SETTINGSP Ane. Getforcurrentview ().
                commandsrequested-= oncommandsrequested;
            _commandsrequestedregistered = false; }//Add a settings item, that is, initialize the custom settings item private void Btnaddsettings_click_1 (object sender, RoutedEventArgs E
 ) {if (!_commandsrequestedregistered)           {///register the Settingspane commandsrequested event Settingspane.getforcurrentview ().
                commandsrequested + = oncommandsrequested;
            _commandsrequestedregistered = true;
                else {Lblmsg.text = "has registered a commandsrequested event for Settingspane";
            Lblmsg.text + = Environment.NewLine; 
        }//Show Settingspane private void Btnshowsettings_click_1 (object sender, RoutedEventArgs e)
        {settingspane.show ();
        } void oncommandsrequested (Settingspane settingspane, Settingspanecommandsrequestedeventargs EventArgs) {//Initialize the settings item in Settingspane Uicommandinvokedhandler handler = new Uicommandinvokedhandler (onset
    
            Tingscommand);
            Settingscommand Aboutcommand = new Settingscommand ("about", "about", handler);
    
EVENTARGS.REQUEST.APPLICATIONCOMMANDS.ADD (Aboutcommand);            Settingscommand Contactcommand = new Settingscommand ("ContactUs", "Contact Us", handler);
    
            EVENTARGS.REQUEST.APPLICATIONCOMMANDS.ADD (Contactcommand);
            Settingscommand Flyoutcommand = new Settingscommand ("Flyout", "Pop-up a class" setting "Style detail Settings page", handler);
        EVENTARGS.REQUEST.APPLICATIONCOMMANDS.ADD (Flyoutcommand); The command void Onsettingscommand (Iuicommand command) {S of each custom setting item in the Settingspane response
            Ettingscommand Settingscommand = (settingscommand) command; Lblmsg.text = = String.
            Format ("Commandid:{0}-Label:{1}", SettingsCommand.Id.ToString (), Settingscommand.label);
    
            Lblmsg.text + = Environment.NewLine;
                The settingscommand.id is used to determine which setting item the user is using (settingsCommand.Id.ToString () = = "Flyout") {
    
                Set the width of the page in detail double settingspagewidth = 600; Set the basic properties for the Popup that carries the detail Settings page _settingspopup.islighTdismissenabled = true;
                _settingspopup.width = Settingspagewidth;
    
                _settingspopup.height = Window.Current.Bounds.Height;
                Add Panethemetransition effect to pop-up box _settingspopup.childtransitions = new Transitioncollection (); _settingspopup.childtransitions.add (New Panethemetransition () {Edge = Edgetran
    
                Sitionlocation.right});
                Instantiate the Custom Detail Settings page and put it inside the Popup customsettingspage mysettingspage = new Customsettingspage ();
                Mysettingspage.width = Settingspagewidth;
                Mysettingspage.height = Window.Current.Bounds.Height;
    
                _settingspopup.child = Mysettingspage;
                Specifies the display location of the Popup _settingspopup.horizontaloffset = window.current.bounds.width-settingspagewidth;
                _settingspopup.verticaloffset = 0; _settingspopup.isopen = TRUe }
        }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.