Exemplo n.º 1
0
 private void ApplicationView_Activated(CoreApplicationView sender, IActivatedEventArgs args)
 {
     CoreWindow.GetForCurrentThread().Activate();
 }
        /// <summary>
        /// Determines whether the ctrl key is pressed.
        /// </summary>
        /// <returns></returns>
        protected virtual bool IsCtrlDown()
        {
            var state = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.LeftControl);

            return((state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down);
        }
Exemplo n.º 3
0
 // Creates ViewLifetimeControl for the particular view.
 // Only do this once per view.
 public static ViewLifetimeControl CreateForCurrentView()
 {
     return(new ViewLifetimeControl(CoreWindow.GetForCurrentThread()));
 }
Exemplo n.º 4
0
 public AudioRecorder()
 {
     this.InitializeComponent();
     dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
 }
 // Creates ViewLifetimeControl for the particular view.
 // Only do this once per view.
 public static ViewLifetimeManager CreateForCurrentView()
 {
     return(new ViewLifetimeManager(CoreWindow.GetForCurrentThread()));
 }
Exemplo n.º 6
0
        private static bool IsUIThread()
        {
            CoreWindow window = CoreWindow.GetForCurrentThread();

            return(window != null && window.Dispatcher != null && window.Dispatcher.HasThreadAccess);
        }
Exemplo n.º 7
0
        public static bool IsOnUIThread()
        {
            CoreWindow coreWindow = CoreWindow.GetForCurrentThread();

            return(coreWindow != null && coreWindow.Dispatcher.HasThreadAccess);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Custom keyboarding logic to enable movement via the arrow keys without triggering selection
        /// until a 'Space' or 'Enter' key is pressed.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(KeyRoutedEventArgs e)
        {
            var focusedItem = FocusManager.GetFocusedElement();

            switch (e.Key)
            {
            case VirtualKey.Up:
                this.TryMoveFocus(FocusNavigationDirection.Up);
                e.Handled = true;
                break;

            case VirtualKey.Down:
                this.TryMoveFocus(FocusNavigationDirection.Down);
                e.Handled = true;
                break;

            case VirtualKey.Tab:
                var shiftKeyState = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift);
                var shiftKeyDown  = (shiftKeyState & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;

                // If we're on the header item then this will be null and we'll still get the default behavior.
                if (focusedItem is ListViewItem)
                {
                    var  currentItem = (ListViewItem)focusedItem;
                    bool onlastitem  = currentItem != null && this.IndexFromContainer(currentItem) == this.Items.Count - 1;
                    bool onfirstitem = currentItem != null && this.IndexFromContainer(currentItem) == 0;

                    if (!shiftKeyDown)
                    {
                        if (onlastitem)
                        {
                            this.TryMoveFocus(FocusNavigationDirection.Next);
                        }
                        else
                        {
                            this.TryMoveFocus(FocusNavigationDirection.Down);
                        }
                    }
                    else     // Shift + Tab
                    {
                        if (onfirstitem)
                        {
                            this.TryMoveFocus(FocusNavigationDirection.Previous);
                        }
                        else
                        {
                            this.TryMoveFocus(FocusNavigationDirection.Up);
                        }
                    }
                }
                else if (focusedItem is Control)
                {
                    if (!shiftKeyDown)
                    {
                        this.TryMoveFocus(FocusNavigationDirection.Down);
                    }
                    else     // Shift + Tab
                    {
                        this.TryMoveFocus(FocusNavigationDirection.Up);
                    }
                }

                e.Handled = true;
                break;

            case VirtualKey.Space:
            case VirtualKey.Enter:
                // Fire our event using the item with current keyboard focus
                this.InvokeItem(focusedItem);
                e.Handled = true;
                break;

            default:
                base.OnKeyDown(e);
                break;
            }
        }
Exemplo n.º 9
0
 public PointerRoutedEventArgs()
 {
     // This is acceptable as all ctors of this class are internal
     CoreWindow.GetForCurrentThread().SetLastPointerEvent(this);
 }
Exemplo n.º 10
0
 public ViewModelBase() : this(CoreWindow.GetForCurrentThread().Dispatcher)
 {
 }
Exemplo n.º 11
0
 public override void OnNavigatingFrom(NavigatingEventArgs e)
 {
     CoreWindow.GetForCurrentThread().KeyDown -= UserTimeoutViewModel_KeyDown;
     base.OnNavigatingFrom(e);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Runs a process.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="workingDirectory">The working directory.</param>
        public async Task StartProcessAsync(string fileName, string arguments, string workingDirectory = null)
        {
            //  Are we showing diagnostics?
            if (ShowDiagnostics)
            {
                await WriteOutputAsync("Preparing to run " + fileName, Color.FromArgb(255, 0, 255, 0));

                if (!string.IsNullOrEmpty(arguments))
                {
                    await WriteOutputAsync(" with arguments " + arguments + "." + Environment.NewLine, Color.FromArgb(255, 0, 255, 0));
                }
                else
                {
                    await WriteOutputAsync("." + Environment.NewLine, Color.FromArgb(255, 0, 255, 0));
                }
            }


            await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    var result = await ProcessLauncher.RunToCompletionAsync(
                        fileName,
                        arguments,
                        new ProcessLauncherOptions
                    {
                        WorkingDirectory = workingDirectory,
                        StandardOutput   = OutputStream,
                        StandardError    = ErrorStream
                    });

                    using (var outStreamRedirect = OutputStream.GetInputStreamAt(0))
                    {
                        var size = OutputStream.Size;
                        using (var dataReader = new DataReader(outStreamRedirect))
                        {
                            var bytesLoaded = await dataReader.LoadAsync((uint)size);
                            var stringRead  = dataReader.ReadString(bytesLoaded);
                            await WriteOutputAsync(stringRead, Colors.White);
                        }
                    }

                    using (var errStreamRedirect = ErrorStream.GetInputStreamAt(0))
                    {
                        using (var dataReader = new DataReader(errStreamRedirect))
                        {
                            var size        = ErrorStream.Size;
                            var bytesLoaded = await dataReader.LoadAsync((uint)size);
                            var stringRead  = dataReader.ReadString(bytesLoaded);
                            await WriteOutputAsync(stringRead, Colors.Red);
                        }
                    }
                }
                catch (UnauthorizedAccessException uex)
                {
                    await WriteOutputAsync($"Exception Thrown: {uex.Message}{Environment.NewLine}", Colors.Red);
                    await WriteOutputAsync($"Make sure you're allowed to run the specified exe; either{Environment.NewLine}" +
                                           $"\t1) Add the exe to the AppX package, or{Environment.NewLine}" +
                                           $"\t2) Add the absolute path of the exe to the allow list:{Environment.NewLine}" +
                                           $"\t\tHKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\EmbeddedMode\\ProcessLauncherAllowedExecutableFilesList.{Environment.NewLine}{Environment.NewLine}" +
                                           $"Also, make sure the <iot:Capability Name=\"systemManagement\" /> has been added to the AppX manifest capabilities.{Environment.NewLine}", Colors.Red);
                }
                catch (Exception ex)
                {
                    await WriteOutputAsync($"Exception Thrown: {ex.Message}{Environment.NewLine}", Colors.Red);
                    await WriteOutputAsync($"{ex.StackTrace}{Environment.NewLine}", Colors.Red);
                }
            });
        }
 public Scenario2ViewModel()
 {
     m_dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
     m_rootPage   = MainPage.Current;
 }
Exemplo n.º 14
0
        public GamePage()
        {
            this.InitializeComponent();

            _toolButtonBrush = (SolidColorBrush)this.Resources["ToolBarButtonBackground"];
            _borderBrush     = (SolidColorBrush)this.Resources["BorderBrush"];

            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

            VersionTextBlock.Text = GetAppVersion();

            GazeInput.DwellFeedbackCompleteBrush = new SolidColorBrush(Colors.Transparent);

            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            LoadedImageSurface loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/BorderDot.png"), new Size(_cellSize, _cellSize));

            _breadCrumbBrush         = _compositor.CreateSurfaceBrush();
            _breadCrumbBrush.Surface = loadedSurface;

            _numRows = MIN_ROWS;

            _mazeRunner = new Image
            {
                Source            = new BitmapImage(new Uri(this.BaseUri, "/Assets/luna.png")),
                VerticalAlignment = VerticalAlignment.Center
            };

            _mazeEnd = new Image
            {
                Source            = new BitmapImage(new Uri(this.BaseUri, "/Assets/doghouse.png")),
                VerticalAlignment = VerticalAlignment.Center
            };

            _mazeComplete = new Image
            {
                Source            = new BitmapImage(new Uri(this.BaseUri, "/Assets/dogInHouse.png")),
                VerticalAlignment = VerticalAlignment.Center
            };

            _newSolidBorderThickness = new Thickness(_borderThickness);
            _newButtonStyle          = (Style)this.Resources["MazeCellStyle"];

            _mazeCreator = Creator.GetCreator();

            _solutionTimer          = new DispatcherTimer();
            _solutionTimer.Interval = TimeSpan.FromSeconds(0.1);
            _solutionTimer.Tick    += OnSolutionTimerTick;

            _cellCreationTimer          = new DispatcherTimer();
            _cellCreationTimer.Interval = TimeSpan.FromMilliseconds(50);
            _cellCreationTimer.Tick    += OnCellCreationTimer_Tick;

            _openCellTimer          = new DispatcherTimer();
            _openCellTimer.Interval = TimeSpan.FromMilliseconds(50);
            _openCellTimer.Tick    += OnOpenCellTimer_Tick;

            _mazeCells   = new List <Point>();
            _breadCrumbs = new List <Point>();

            Loaded += GamePage_Loaded;

            CoreWindow.GetForCurrentThread().KeyDown += new Windows.Foundation.TypedEventHandler <CoreWindow, KeyEventArgs>(delegate(CoreWindow sender, KeyEventArgs args) {
                GazeInput.GetGazePointer(this).Click();
            });

            var sharedSettings = new ValueSet();

            GazeSettingsHelper.RetrieveSharedSettings(sharedSettings).Completed = new AsyncActionCompletedHandler((asyncInfo, asyncStatus) =>
            {
                GazeInput.LoadSettings(sharedSettings);
            });
        }