コード例 #1
0
        public void AddMenuItem(string moniker, string iconFilePath)
        {
            if (_radialController.Menu.Items.Any(i => i.DisplayText == moniker))
            {
                return;
            }

            IAsyncOperation <StorageFile> operation = StorageFile.GetFileFromPathAsync(iconFilePath);

            operation.Completed += (asyncInfo, asyncStatus) =>
            {
                if (asyncStatus == AsyncStatus.Completed)
                {
                    StorageFile file     = asyncInfo.GetResults();
                    var         stream   = RandomAccessStreamReference.CreateFromFile(file);
                    var         menuItem = RadialControllerMenuItem.CreateFromIcon(moniker, stream);

                    menuItem.Invoked += (sender, args) =>
                    {
                        _status.UpdateSelectedItem(sender.DisplayText);
                        _controllers.FirstOrDefault(c => c.Moniker == moniker)?.OnActivate();
                    };

                    ThreadHelper.Generic.BeginInvoke(DispatcherPriority.Normal, () =>
                    {
                        _radialController.Menu.Items.Add(menuItem);
                    });
                }
            };
        }