今日 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 設置面版還是挺簡單的,我這里只是學習寫了一些簡單的東西,并記錄下,方便自己以后再次學習。當然,里面的自定義控件的復雜邏輯還是要靠自己去寫的。