當前位置: 首頁>>代碼示例>>C#>>正文


C# Button.AddHandler方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.Controls.Button.AddHandler方法的典型用法代碼示例。如果您正苦於以下問題:C# Button.AddHandler方法的具體用法?C# Button.AddHandler怎麽用?C# Button.AddHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.Controls.Button的用法示例。


在下文中一共展示了Button.AddHandler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoadKeyboard

        /// <summary>Load a specific keyboard from its definition file.</summary>
        /// <param name="uri">The location of the keyboard definition file.</param>
        /// <param name="style">The style to use for a keyboard key.</param>
        /// <returns>An async task,</returns>
        private async Task LoadKeyboard(Uri uri, Style style)
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
            using (var stream = await file.OpenStreamForReadAsync())
            {
                var textReader = (TextReader)new StreamReader(stream);
                string line;
                Dictionary<int, KeyInfo> allkeys = new Dictionary<int, KeyInfo>();
                var hasAltGrKey = false;
                var readKeys = false;
                var readDeadKeys = false;
                while (null != (line = await textReader.ReadLineAsync()))
                {
                    if (string.IsNullOrWhiteSpace(line) ||
                        line.StartsWith("#"))
                    {
                        continue;
                    }

                    if (line == "[Keys]")
                    {
                        readKeys = true;
                        readDeadKeys = false;
                    }
                    else if (line == "[DeadKeys]")
                    {
                        readKeys = false;
                        readDeadKeys = true;
                    }
                    else if (readKeys)
                    {
                        int row, col, span;
                        var info = this.ReadKeyDefinition(line, out row, out col, out span);
                        if (info == null)
                        {
                            continue;
                        }

                        hasAltGrKey |= info.HasAltGrCode;
                        allkeys[info.Scancode] = info;

                        this.Invoke(() =>
                        {
                            var button = new Button();
                            button.Content = info[SymbolIndex.Normal].Label;
                            Grid.SetColumn(button, col);
                            Grid.SetRow(button, row);
                            Grid.SetColumnSpan(button, span);
                            button.Style = style;
                            button.Tag = info;
                            button.IsTabStop = false;

                            button.AddHandler(UIElement.PointerPressedEvent, (PointerEventHandler)this.ButtonPressed, true);
                            button.AddHandler(UIElement.PointerReleasedEvent, (PointerEventHandler)this.ButtonReleased, true);
                            button.AddHandler(UIElement.PointerExitedEvent, (PointerEventHandler)this.ButtonReleased, true);

                            this.MainGrid.Children.Add(button);
                        });
                    }
                    else if (readDeadKeys)
                    {
                        this.ReadDeadKeyDefinition(line, allkeys);
                    }
                }

                this.allKeys = allkeys;
                this.usesAltGr = hasAltGrKey;
            }
        }
開發者ID:PollRobots,項目名稱:OldManOfTheVNC,代碼行數:73,代碼來源:Keyboard.xaml.cs


注:本文中的Windows.UI.Xaml.Controls.Button.AddHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。