时间:2014-10-17 09:48:07 来源: 复制分享
今日 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、添加命令道设置面版中. 分别添加了三个命令。以及三个命令对应的操作。这里定义的很简单,自己可以定义的更复杂一些。
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 设置面版还是挺简单的,我这里只是学习写了一些简单的东西,并记录下,方便自己以后再次学习。当然,里面的自定义控件的复杂逻辑还是要靠自己去写的。