• Win 8 自定义设置面版


    今日 10 点,上海,微软中国在 Windows 8 10 月 26 日的全球正式发布前,带我们先睹这全新的系统和硬件的魅力所在!

    微软全球 Windows 与 Windows Live 事业部总裁 Steven Sinofsky 和微软全球资深副总裁、大中华区董事长兼首席执行官贺乐赋( Ralph Haupter )共同出席了庆祝活动。

    漫长的等待,Win 8 终于快发布了。期待中。。。

    下面是我自己学习的Win 8小Sample,为了以后方便学习,特做一些记录。

    效果如下图: 右边添加了三个命令,分别为:First Custom Command,Second Custom Command,Third Custom Command。

    图1-设置面版

    图2-自定义用户控件 右边的控件是用户自己定义的控件,我这里定义的很简单。

    关键代码如下:

    1、添加命令道设置面版中. 分别添加了三个命令。以及三个命令对应的操作。这里定义的很简单,自己可以定义的更复杂一些。

    View Code
            private void AddCommandToSettingPanel()
            {
                //Add three command to Setting Panel.
                SettingsCommand cmd1 = new SettingsCommand("1", "First Custom Command",
                    c =>
                    {
                        SettingPanelUC uc = new SettingPanelUC();
                        uc.Show();
                    });
                SettingsCommand cmd2 = new SettingsCommand("2", "Second Custom Command",
                    c =>
                    {
                        ShowMessageTBK.Text = "Second Custom Command Click";
                    });
                SettingsCommand cmd3 = new SettingsCommand("3", "Third Custom Command",
                    c =>
                    {
                        ShowMessageTBK.Text = "Third Custom Command Click";
                    });
    
                //Add command in CommandsRequested Event.
                SettingsPane.GetForCurrentView().CommandsRequested += (sp, arg) =>
                {
                    arg.Request.ApplicationCommands.Add(cmd1);
                    arg.Request.ApplicationCommands.Add(cmd2);
                    arg.Request.ApplicationCommands.Add(cmd3);
                };
            }

    2、显示设置面版

            private void ShowSettingsPanel(object sender, RoutedEventArgs e)
            {
                //Show Setting Panel
                Windows.UI.ApplicationSettings.SettingsPane.Show();
            }

    3、自定义控件关键代码:

    public sealed partial class SettingPanelUC : UserControl
        {
            Popup pop = null;
            public SettingPanelUC()
            {
                this.InitializeComponent();
                this.Width = 360d;
                this.Height = Window.Current.Bounds.Height;
                this.pop = new Popup();
                this.pop.Child = this;
                this.pop.IsLightDismissEnabled = true;
    
                //Make the user control is on the right.
                pop.HorizontalOffset = Window.Current.Bounds.Width - this.Width;
                pop.VerticalOffset = 0d;
    
                //Animation for the user control.
                this.Transitions = new Windows.UI.Xaml.Media.Animation.TransitionCollection();
                EdgeUIThemeTransition et = new EdgeUIThemeTransition();
                et.Edge = EdgeTransitionLocation.Right;
                this.Transitions.Add(et);         
            }
    
            /// <summary>
            /// 显示控件
            /// </summary>
            public void Show()
            {
                if (pop != null)
                {
                    pop.IsOpen = true;
                }
            }
    
            /// <summary>
            /// 隐藏控件
            /// </summary>
            public void Hide()
            {
                if (pop != null)
                {
                    pop.IsOpen = false;
                }
            }
    
            private void Back(object sender, RoutedEventArgs e)
            {
                this.Hide();
                Windows.UI.ApplicationSettings.SettingsPane.Show();
            }
        }

    总结:Win 8 设置面版还是挺简单的,我这里只是学习写了一些简单的东西,并记录下,方便自己以后再次学习。

    希望园子里的朋友能多多指教,我也是一名Win 8 初学者。当然,里面的自定义控件的复杂逻辑还是要靠自己去写的。

    作者:Work Hard Work Smart
    出处:http://www.cnblogs.com/linlf03/
    欢迎任何形式的转载,未经作者同意,请保留此段声明!

  • 相关阅读:
    WAMP 2.2 配置与IIS共用单IP,多域名多网站配置方法
    [.NET MVC4 入门系列00]目录
    [.NET MVC4 入门系列04]Controller和View间交互原理
    [.NET MVC4 入门系列05]添加自定义查询页Search
    [.NET MVC4 入门系列02]MVC Movie 为项目添加Model
    [.NET MVC4 入门系列07] 在Model模型模块中添加验证
    [.NET MVC4 入门系列03]使用Controller访问Model中数据
    DateTime 类常用技巧
    Access 注意地方
    互联网公司老板的十大谎言,别对号入座
  • 原文地址:https://www.cnblogs.com/linlf03/p/2735450.html
Copyright © 2020-2023  润新知