public static Task RunAsync(Action action, CoreDispatcher dispatcher = null)
        {
            if (action == null)
            {
                return Task.FromResult((object)null);
            }

            try
            {
                dispatcher = dispatcher ?? CoreApplication.MainView.CoreWindow.Dispatcher;

                return dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    new DispatchedHandler(action)).AsTask()
                    .ContinueWith(
                    t =>
                    {
                        if (t.IsFaulted && t.Exception != null)
                        {
                            CoreEventSource.Log.LogVerbose(
                                "Got an exception from an action using the UI dispatcher: " +
                                t.Exception.ToString());
                        }
                    });
            }
            catch (Exception exception)
            {
                CoreEventSource.Log.LogVerbose("Got an exception from an action using the UI dispatcher: " + exception);
                return Task.FromResult((object)null);
            }
        }
示例#2
0
        private void OnAcceleratorKeyActivated( CoreDispatcher sender, AcceleratorKeyEventArgs args )
        {
            Contract.Requires( args != null );

            // only investigate further when Left, Right, or the dedicated Previous or Next keys are pressed
            var virtualKey = args.VirtualKey;
            var shouldHandle = ( args.EventType == SystemKeyDown || args.EventType == KeyDown ) && ( virtualKey == Left || virtualKey == Right || (int) virtualKey == 166 || (int) virtualKey == 167 );

            if ( !shouldHandle )
                return;

            var window = Window.Current.CoreWindow;
            var down = CoreVirtualKeyStates.Down;
            var menuKey = ( window.GetKeyState( Menu ) & down ) == down;
            var controlKey = ( window.GetKeyState( Control ) & down ) == down;
            var shiftKey = ( window.GetKeyState( Shift ) & down ) == down;
            var noModifiers = !menuKey && !controlKey && !shiftKey;
            var onlyAlt = menuKey && !controlKey && !shiftKey;
            var frame = AssociatedObject.Frame;

            if ( ( ( (int) virtualKey == 166 && noModifiers ) || ( virtualKey == Left && onlyAlt ) ) && frame.CanGoBack )
            {
                // navigate back when the previous key or Alt+Left are pressed
                frame.GoBack();
                args.Handled = true;
            }
            else if ( ( ( (int) virtualKey == 167 && noModifiers ) || ( virtualKey == Right && onlyAlt ) ) && frame.CanGoBack )
            {
                // navigate forward when the next key or Alt+Right are pressed
                frame.GoForward();
                args.Handled = true;
            }
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of the type.
        /// </summary>
        public BackgroundWorker()
        {
#if NETFX_CORE
            _dispatcher = Dispatcher;
#else
            _dispatcher = get_Dispatcher();
#endif
        }
示例#4
0
		public MjpegDecoder()
		{
#if !XNA && !WINRT
			_context = SynchronizationContext.Current;

			BitmapImage = new BitmapImage();
#elif WINRT
			if(CoreWindow.GetForCurrentThread() != null)
				_dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
#endif
		}
示例#5
0
        public FileProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, ProgressBar progressBar, ListedItem item, IShellPage instance)
        {
            ViewModel   = viewModel;
            TokenSource = tokenSource;
            ProgressBar = progressBar;
            Dispatcher  = coreDispatcher;
            Item        = item;
            AppInstance = instance;

            GetBaseProperties();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
 public void Initialize()
 {
     MainViewId     = ApplicationView.GetForCurrentView().Id;
     MainDispatcher = Window.Current.Dispatcher;
 }
示例#7
0
        public FolderProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, ListedItem item)
        {
            ViewModel   = viewModel;
            TokenSource = tokenSource;
            Dispatcher  = coreDispatcher;
            Item        = item;

            GetBaseProperties();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
示例#8
0
 public bool TryEnterFullScreenMode()
 {
     CoreDispatcher.CheckThreadAccess();
     UpdateFullScreenMode(true);
     return(true);
 }
示例#9
0
 public TextKeyboardDismissViewModel(CoreDispatcher dispatcher) : base(dispatcher)
 {
     HideField = new DelegateCommand(ExecuteHideField);
 }
示例#10
0
 public ImageWithLateSourceViewModel(CoreDispatcher dispatcher) : base(dispatcher)
 {
 }
 public WindowsPhoneSilverlightRunner(CoreDispatcher dispatcher, TextBlock textBlock)
 {
     _dispatcher = dispatcher;
     _output     = textBlock;
 }
示例#12
0
 public static Task RunDirectlyOrDispatchAsyncAsync(this CoreDispatcher dispatcher, Func <CancellationToken, Task> func, CancellationToken cancellationToken)
 {
     return(dispatcher.RunDirectlyOrDispatchAsyncAsync(async innerCt => { await func(innerCt).ConfigureAwait(false); return 0; }, cancellationToken));
 }
示例#13
0
 public CommandPanelViewModel()
 {
     _dispatcher = Window.Current.Dispatcher;
     FontSize    = 10;
 }
示例#14
0
 public DispatcherWrapper(CoreDispatcher dispatcher)
 {
     DebugWrite(caller: "Constructor");
     this.dispatcher = dispatcher;
 }
示例#15
0
 public SyncDialog(CoreDispatcher dispatcher)
 {
     this.InitializeComponent();
     this.dispatcher = dispatcher;
 }
示例#16
0
 public Events()
 {
     _events.Clear();
     UIDispatcher = null;
 }
示例#17
0
 public CommandResponse(CoreDispatcher dispatcher, Logger logger) : base(dispatcher, logger)
 {
 }
示例#18
0
 protected DispatcherContext()
 {
     Dispatcher = CoreApplication.CreateNewView().Dispatcher;
 }
示例#19
0
        public HtmlEditor(Grid webViewGrid, FrameworkElement contextMenuPlace, MenuFlyout menuFlyout, string windowSizeName, string htmlFilePath, CoreDispatcher dispatcher)
        {
            this.webViewGrid      = webViewGrid;
            this.ContextMenuPlace = contextMenuPlace;
            this.WindowSizeName   = windowSizeName;
            this.MenuFlyout       = menuFlyout;
            this.htmlFilePath     = htmlFilePath;
            this.dispatcher       = dispatcher;

            AddWebViewControlIntoGrid();

            buttonEventNotify = new ButtonPassingWebToWinRT();
            buttonEventNotify.ButtonClickEvent += ButtonEventNotifyClickEventHandler;

            editableFieldNotify = new EditableFieldPassWebToWinRT();
            editableFieldNotify.EditableFieldTextChangedEvent += EditableFieldTextChangedEventHandler;
            editableFieldNotify.EditableFieldPasteEvent       += EditablePasteEventHandler;
            editableFieldNotify.EditableContextMenuEvent      += EditableFieldContextMenuEventHandler;
        }
示例#20
0
 public UwpBridgeService(CoreDispatcher dispatcher, Windows.UI.Xaml.Controls.WebView webview, ContentControl inAppNotification)
 {
     Webview           = webview;
     InAppNotification = inAppNotification;
     Dispatcher        = dispatcher;
 }
 public SignalWindowsFrontend(CoreDispatcher dispatcher, ViewModelLocator locator, int viewId)
 {
     Dispatcher = dispatcher;
     Locator    = locator;
     ViewId     = viewId;
 }
示例#22
0
 public static Task RunDirectlyOrDispatchAsync(this CoreDispatcher dispatcher, Action action, CancellationToken cancellationToken)
 {
     return(dispatcher.RunDirectlyOrDispatchAsync(() => { action(); return 0; }, cancellationToken));
 }
示例#23
0
        public LibraryProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, LibraryItem item, IShellPage instance)
        {
            ViewModel   = viewModel;
            TokenSource = tokenSource;
            Dispatcher  = coreDispatcher;
            Library     = item;
            AppInstance = instance;

            GetBaseProperties();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
示例#24
0
        //protected override async void OnKeyDown(KeyRoutedEventArgs e)
        //{
        //    if (e.Key == VirtualKey.Enter)
        //    {
        //        // Check if CTRL or Shift is also pressed in addition to Enter key.
        //        var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
        //        var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift);

        //        // If there is text and CTRL/Shift is not pressed, send message. Else allow new row.
        //        if (!ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down) && !IsEmpty)
        //        {
        //            e.Handled = true;
        //            await SendAsync();
        //        }
        //    }

        //    base.OnKeyDown(e);
        //}

        private async void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
        {
            if (args.VirtualKey == VirtualKey.Enter && FocusState != FocusState.Unfocused)
            {
                // Check if CTRL or Shift is also pressed in addition to Enter key.
                var ctrl  = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
                var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift);
                var key   = Window.Current.CoreWindow.GetKeyState(args.VirtualKey);

                if (UsernameHints != null && ViewModel.UsernameHints != null)
                {
                    var send = key.HasFlag(CoreVirtualKeyStates.Down) && !ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down);
                    if (send)
                    {
                        AcceptsReturn = false;
                        var container = UsernameHints.ContainerFromIndex(Math.Max(0, UsernameHints.SelectedIndex)) as ListViewItem;
                        if (container != null)
                        {
                            var peer       = new ListViewItemAutomationPeer(container);
                            var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                            invokeProv.Invoke();
                        }
                    }
                    else
                    {
                        AcceptsReturn = true;
                    }

                    return;
                }

                if (BotCommands != null && ViewModel.BotCommands != null)
                {
                    var send = key.HasFlag(CoreVirtualKeyStates.Down) && !ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down);
                    if (send)
                    {
                        AcceptsReturn = false;
                        var container = BotCommands.ContainerFromIndex(Math.Max(0, BotCommands.SelectedIndex)) as ListViewItem;
                        if (container != null)
                        {
                            var peer       = new ListViewItemAutomationPeer(container);
                            var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                            invokeProv.Invoke();
                        }
                    }
                    else
                    {
                        AcceptsReturn = true;
                    }

                    return;
                }

                // If there is text and CTRL/Shift is not pressed, send message. Else allow new row.
                if (ApplicationSettings.Current.IsSendByEnterEnabled)
                {
                    var send = key.HasFlag(CoreVirtualKeyStates.Down) && !ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down);
                    if (send)
                    {
                        AcceptsReturn = false;
                        await SendAsync();
                    }
                    else
                    {
                        AcceptsReturn = true;
                    }
                }
                else
                {
                    var send = key.HasFlag(CoreVirtualKeyStates.Down) && ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down);
                    if (send)
                    {
                        AcceptsReturn = false;
                        await SendAsync();
                    }
                    else
                    {
                        AcceptsReturn = true;
                    }
                }
            }
        }
 public NativeStorageRuntimeTestsViewModel(CoreDispatcher dispatcher) : base(dispatcher)
 {
 }
示例#26
0
 public static void BeginInvoke(this CoreDispatcher dispatcher, Action action)
 {
     var asyncAction = dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(action));
 }
示例#27
0
 public PedometerTestsViewModel(CoreDispatcher dispatcher) :
     base(dispatcher)
 {
 }
示例#28
0
 public MainPage()
 {
     this.InitializeComponent();
     _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
 }
        /// <summary>
        /// Invoked on every keystroke, including system keys such as Alt key combinations, when
        /// this page is active and occupies the entire window.  Used to detect keyboard navigation
        /// between pages even when the page itself doesn't have focus.
        /// </summary>
        /// <param name="sender">Instance that triggered the event.</param>
        /// <param name="e">Event data describing the conditions that led to the event.</param>
        private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender,
            AcceleratorKeyEventArgs e)
        {
            var virtualKey = e.VirtualKey;

            // Only investigate further when Left, Right, or the dedicated Previous or Next keys
            // are pressed
            if ((e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown ||
                e.EventType == CoreAcceleratorKeyEventType.KeyDown) &&
                (virtualKey == VirtualKey.Left || virtualKey == VirtualKey.Right ||
                (int)virtualKey == 166 || (int)virtualKey == 167))
            {
                var coreWindow = Window.Current.CoreWindow;
                var downState = CoreVirtualKeyStates.Down;
                bool menuKey = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
                bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
                bool shiftKey = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;
                bool noModifiers = !menuKey && !controlKey && !shiftKey;
                bool onlyAlt = menuKey && !controlKey && !shiftKey;

                if (((int)virtualKey == 166 && noModifiers) ||
                    (virtualKey == VirtualKey.Left && onlyAlt))
                {
                    // When the previous key or Alt+Left are pressed navigate back
                    e.Handled = true;
                    this.GoBackCommand.Execute(null);
                }
                else if (((int)virtualKey == 167 && noModifiers) ||
                    (virtualKey == VirtualKey.Right && onlyAlt))
                {
                    // When the next key or Alt+Right are pressed navigate forward
                    e.Handled = true;
                    this.GoForwardCommand.Execute(null);
                }
            }
        }
示例#30
0
 public static void Initialize()
 {
     _dispatcher = Window.Current.CoreWindow.Dispatcher;
 }
示例#31
0
 internal CrossUIItemClone(CrossUIItem <T> source, CoreDispatcher dispatcher)
 {
     _source          = source;
     _dispatcher      = dispatcher;
     _source.Updated += Source_Updated;
 }
示例#32
0
文件: Runner.cs 项目: mrange/bikes
 public Runner(CoreDispatcher coreDispatcher)
 {
     CoreDispatcher = coreDispatcher ?? CoreWindow.GetForCurrentThread().Dispatcher;
 }
 static DispatcherExt()
 {
     Dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
 }
 /// <summary>
 /// Runs the event dispatcher and awaits for it to complete before returning the results for dispatched events asynchronously.
 /// </summary>
 /// <param name="dispatcher">The dispatcher.</param>
 /// <param name="action">The action to call.</param>
 /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
 public static Task RunAndAwaitAsync(this CoreDispatcher dispatcher, Action action)
 {
     return(dispatcher.RunAndAwaitAsync(CoreDispatcherPriority.Normal, action));
 }
 /// <summary>
 /// Creates a DispatcherBindableBase instance.
 /// </summary>
 /// <param name="uiDispatcher">Core event message dispatcher.</param>
 protected DispatcherBindableBase(CoreDispatcher uiDispatcher)
 {
     _uiDispatcher = uiDispatcher;
 }
 /// <summary>
 /// Runs the event dispatcher and awaits for it to complete before returning the results for dispatched events asynchronously.
 /// </summary>
 /// <typeparam name="T">The return type.</typeparam>
 /// <param name="dispatcher">The dispatcher.</param>
 /// <param name="function">The function to call.</param>
 /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
 public static Task <T> RunAndAwaitAsync <T>(this CoreDispatcher dispatcher, Func <T> function)
 {
     return(dispatcher.RunAndAwaitAsync(CoreDispatcherPriority.Normal, function));
 }
示例#37
0
 private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
 {
     if (args.EventType.ToString().Contains("Down"))
     {
         // 按下Esc键则退出图片详情
         if (args.VirtualKey == Windows.System.VirtualKey.Escape)
         {
             foreach (var item in PopupUserControlList)
             {
                 if (item.GetType() == typeof(ImageMaskControl))
                 {
                     var t = (ImageMaskControl)item;
                     t.Close();
                     break;
                 }
             }
         }
         // 向左或向上切换上一张图片,没有则弹出提醒
         else if (args.VirtualKey == VirtualKey.Left || args.VirtualKey == VirtualKey.Up)
         {
             foreach (var item in PopupUserControlList)
             {
                 if (item.GetType() == typeof(ImageMaskControl))
                 {
                     var t           = (ImageMaskControl)item;
                     var oldImg      = t.imageFile;
                     var groupimages = App.Db.Images.Where(p => p.GroupId == oldImg.GroupId).ToList();
                     int index       = groupimages.IndexOf(oldImg);
                     if (index != -1 && index > 0)
                     {
                         t.Init(groupimages[index - 1]);
                         break;
                     }
                     else
                     {
                         new PopupMaskTip(AppTools.GetReswLanguage("IsFirstImage")).Show();
                         break;
                     }
                 }
             }
         }
         // 向右或向下切换下一张图片,没有则弹出提醒
         else if (args.VirtualKey == VirtualKey.Right || args.VirtualKey == VirtualKey.Down)
         {
             foreach (var item in PopupUserControlList)
             {
                 var t           = (ImageMaskControl)item;
                 var oldImg      = t.imageFile;
                 var groupimages = App.Db.Images.Where(p => p.GroupId == oldImg.GroupId).ToList();
                 int index       = groupimages.IndexOf(oldImg);
                 if (index != -1 && index < groupimages.Count - 1)
                 {
                     t.Init(groupimages[index + 1]);
                     break;
                 }
                 else
                 {
                     new PopupMaskTip(AppTools.GetReswLanguage("IsLastImage")).Show();
                     break;
                 }
             }
         }
     }
 }