当前位置: 首页>>代码示例>>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;未经允许,请勿转载。