public override IDisposable ActionSheet(ActionSheetConfig config) { var sheet = new CustomMessageBox { Caption = config.Title }; if (config.Cancel != null) { sheet.IsRightButtonEnabled = true; sheet.RightButtonContent = this.CreateButton(config.Cancel.Text, () => { sheet.Dismiss(); config.Cancel.Action?.Invoke(); }); } if (config.Destructive != null) { sheet.IsLeftButtonEnabled = true; sheet.LeftButtonContent = this.CreateButton(config.Destructive.Text, () => { sheet.Dismiss(); config.Destructive.Action?.Invoke(); }); } var list = new ListBox { FontSize = 36, Margin = new Thickness(12.0), SelectionMode = SelectionMode.Single, ItemsSource = config.Options .Select(x => new TextBlock { Text = x.Text, Margin = new Thickness(0.0, 12.0, 0.0, 12.0), DataContext = x }) }; list.SelectionChanged += (sender, args) => sheet.Dismiss(); sheet.Content = new ScrollViewer { Content = list }; sheet.Dismissed += (sender, args) => { var txt = list.SelectedValue as TextBlock; if (txt == null) return; var action = txt.DataContext as ActionSheetOption; action?.Action?.Invoke(); }; return this.DispatchWithDispose(sheet.Show, sheet.Dismiss); }
public Task <ConfirmThreeButtonsResponse> ConfirmThreeButtonsAsync(string message, string title = null, string positive = "Yes", string negative = "No", string neutral = "Maybe") { StackPanel contents = new StackPanel(); contents.Orientation = Orientation.Vertical; var positiveButton = new Button() { Content = positive }; var neutralButton = new Button() { Content = neutral }; var negativeButton = new Button() { Content = negative }; contents.Children.Add(positiveButton); contents.Children.Add(neutralButton); contents.Children.Add(negativeButton); var box = new Microsoft.Phone.Controls.CustomMessageBox() { Caption = title, Message = message, IsLeftButtonEnabled = false, IsRightButtonEnabled = false, Content = contents }; var response = new TaskCompletionSource <ConfirmThreeButtonsResponse>(); positiveButton.Click += (sender, args) => { response.TrySetResult(ConfirmThreeButtonsResponse.Positive); box.Dismiss(); }; neutralButton.Click += (sender, args) => { response.TrySetResult(ConfirmThreeButtonsResponse.Neutral); box.Dismiss(); }; negativeButton.Click += (sender, args) => { response.TrySetResult(ConfirmThreeButtonsResponse.Negative); box.Dismiss(); }; box.Show(); return(response.Task); }
public override void ActionSheet(ActionSheetConfig config) { var sheet = new CustomMessageBox { Caption = config.Title, IsLeftButtonEnabled = false, IsRightButtonEnabled = false }; var list = new ListBox { FontSize = 36, Margin = new Thickness(12.0), SelectionMode = SelectionMode.Single, ItemsSource = config.Options .Select(x => new TextBlock { Text = x.Text, Margin = new Thickness(0.0, 12.0, 0.0, 12.0), DataContext = x }) }; list.SelectionChanged += (sender, args) => sheet.Dismiss(); sheet.Content = list; sheet.Dismissed += (sender, args) => { var txt = (TextBlock)list.SelectedValue; var action = (ActionSheetOption)txt.DataContext; if (action.Action != null) action.Action(); }; this.Dispatch(sheet.Show); }
/// <summary> /// Reveals the message box by inserting it into a popup and opening it. /// </summary> public void Show() { if (_popup != null) { if (_popup.IsOpen) { return; } } LayoutUpdated += CustomMessageBox_LayoutUpdated; _frame = Application.Current.RootVisual as PhoneApplicationFrame; _page = _frame.Content as PhoneApplicationPage; // Change the color of the system tray if necessary. if (SystemTray.IsVisible) { // Cache the original color of the system tray. _systemTrayColor = SystemTray.BackgroundColor; // Change the color of the system tray to match the message box. if (Background is SolidColorBrush) { SystemTray.BackgroundColor = ((SolidColorBrush)Background).Color; } else { SystemTray.BackgroundColor = (Color)Application.Current.Resources["PhoneChromeColor"]; } } // Hide the application bar if necessary. if (_page.ApplicationBar != null) { // Cache the original visibility of the system tray. _hasApplicationBar = _page.ApplicationBar.IsVisible; // Hide it. if (_hasApplicationBar) { _page.ApplicationBar.IsVisible = false; } } else { _hasApplicationBar = false; } // Dismiss the current message box if there is any. if (_currentInstance != null) { _mustRestore = false; CustomMessageBox target = _currentInstance.Target as CustomMessageBox; if (target != null) { _systemTrayColor = target._systemTrayColor; _hasApplicationBar = target._hasApplicationBar; target.Dismiss(); } } _mustRestore = true; // Insert the overlay. Rectangle overlay = new Rectangle(); Color backgroundColor = (Color)Application.Current.Resources["PhoneBackgroundColor"]; overlay.Fill = new SolidColorBrush(Color.FromArgb(0x99, backgroundColor.R, backgroundColor.G, backgroundColor.B)); _container = new Grid(); _container.Children.Add(overlay); // Insert the message box. _container.Children.Add(this); // Create and open the popup. _popup = new Popup(); _popup.Child = _container; SetSizeAndOffset(); _popup.IsOpen = true; _currentInstance = new WeakReference(this); // Attach event handlers. if (_page != null) { _page.BackKeyPress += OnBackKeyPress; _page.OrientationChanged += OnOrientationChanged; } if (_frame != null) { _frame.Navigating += OnNavigating; } }
private void LogOut() { CustomMessageBox messageBox = new CustomMessageBox() { //set the properties Message = ConstantVariable.cfbLogOut, // "Bạn có chắc là bạn muốn thoát tài khoản không?"; LeftButtonContent = ConstantVariable.cfbYes, RightButtonContent = ConstantVariable.cfbNo }; //Add the dismissed event handler messageBox.Dismissed += (s1, e1) => { switch (e1.Result) { case CustomMessageBoxResult.LeftButton: UpdateNotificationURI("Logout"); if (tNetAppSetting.Contains("isLogin")) { tNetAppSetting.Remove("isLogin"); tNetUserLoginData.Remove("UserId"); tNetUserLoginData.Remove("PasswordMd5"); tNetUserLoginData.Remove("RawPassword"); tNetUserLoginData.Remove("UserLmd"); tNetUserLoginData.Remove("PushChannelURI"); NavigationService.Navigate(new Uri("/Pages/Login.xaml", UriKind.Relative)); } break; case CustomMessageBoxResult.RightButton: messageBox.Dismiss(); break; case CustomMessageBoxResult.None: // Do something. break; default: break; } }; //add the show method messageBox.Show(); }
private void ChangeDriverStatus() { CustomMessageBox messageBox = new CustomMessageBox() { //set the properties Message = ConstantVariable.cfbChangeStatus, LeftButtonContent = ConstantVariable.cfbYes, RightButtonContent = ConstantVariable.cfbNo }; //Add the dismissed event handler messageBox.Dismissed += (s1, e1) => { switch (e1.Result) { case CustomMessageBoxResult.LeftButton: ShowLoadingGridScreen(); // Update Status here // Change Button Color Here after change UpdateDriverStatus(ConstantVariable.dStatusAvailable); //Truyền lên AC để chuyển qua NotAvailable //2 CHuyển trạng thái button SetChangeStatusButtonIsRed(); HideLoadingGridScreen(); MessageBox.Show(ConstantVariable.strStatusNotAvaiable);// Không hoạt động break; case CustomMessageBoxResult.RightButton: messageBox.Dismiss(); break; case CustomMessageBoxResult.None: // Do something. break; default: break; } }; messageBox.Show(); }
/// <summary> /// NHẤN NÚT NÀY ĐỂ CHUYỂN QUA TRANG THANH TOÁN /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_TapToPay_Tap(object sender, System.Windows.Input.GestureEventArgs e) { CustomMessageBox messageBox = new CustomMessageBox() { //set the properties Message = ConstantVariable.cfbTapToPay, // "Bạn có chắc là bạn muốn kết thúc chuyến đi không?"; LeftButtonContent = ConstantVariable.cfbYes, RightButtonContent = ConstantVariable.cfbNo }; //Add the dismissed event handler messageBox.Dismissed += (s1, e1) => { switch (e1.Result) { case CustomMessageBoxResult.LeftButton: TapToPay(); break; case CustomMessageBoxResult.RightButton: messageBox.Dismiss(); break; case CustomMessageBoxResult.None: // Do something. break; default: break; } }; //add the show method messageBox.Show(); }
internal Platform(PhoneApplicationPage page) { _tracker.SeparateMasterDetail = true; page.BackKeyPress += OnBackKeyPress; _page = page; _renderer = new Canvas(); _renderer.SizeChanged += RendererSizeChanged; _renderer.Loaded += (sender, args) => UpdateSystemTray(); _tracker.CollectionChanged += (sender, args) => UpdateToolbarItems(); ProgressIndicator indicator; SystemTray.SetProgressIndicator(page, indicator = new ProgressIndicator { IsVisible = false, IsIndeterminate = true }); var busyCount = 0; MessagingCenter.Subscribe(this, Page.BusySetSignalName, (Page sender, bool enabled) => { busyCount = Math.Max(0, enabled ? busyCount + 1 : busyCount - 1); indicator.IsVisible = busyCount > 0; }); MessagingCenter.Subscribe(this, Page.AlertSignalName, (Page sender, AlertArguments arguments) => { var messageBox = new CustomMessageBox { Title = arguments.Title, Message = arguments.Message }; if (arguments.Accept != null) messageBox.LeftButtonContent = arguments.Accept; messageBox.RightButtonContent = arguments.Cancel; messageBox.Show(); _visibleMessageBox = messageBox; messageBox.Dismissed += (o, args) => { arguments.SetResult(args.Result == CustomMessageBoxResult.LeftButton); _visibleMessageBox = null; }; }); MessagingCenter.Subscribe(this, Page.ActionSheetSignalName, (Page sender, ActionSheetArguments arguments) => { var messageBox = new CustomMessageBox { Title = arguments.Title }; var listBox = new ListBox { FontSize = 36, Margin = new System.Windows.Thickness(12) }; var itemSource = new List<string>(); if (!string.IsNullOrWhiteSpace(arguments.Destruction)) itemSource.Add(arguments.Destruction); itemSource.AddRange(arguments.Buttons); if (!string.IsNullOrWhiteSpace(arguments.Cancel)) itemSource.Add(arguments.Cancel); listBox.ItemsSource = itemSource.Select(s => new TextBlock { Text = s, Margin = new System.Windows.Thickness(0, 12, 0, 12) }); messageBox.Content = listBox; listBox.SelectionChanged += (o, args) => messageBox.Dismiss(); messageBox.Dismissed += (o, args) => { string result = listBox.SelectedItem != null ? ((TextBlock)listBox.SelectedItem).Text : null; arguments.SetResult(result); _visibleMessageBox = null; }; messageBox.Show(); _visibleMessageBox = messageBox; }); }
public Task<ConfirmThreeButtonsResponse> ConfirmThreeButtonsAsync(string message, string title = null, string positive = "Yes", string negative = "No", string neutral = "Maybe") { StackPanel contents = new StackPanel(); contents.Orientation = Orientation.Vertical; var positiveButton = new Button() { Content = positive }; var neutralButton = new Button() { Content = neutral }; var negativeButton = new Button() { Content = negative }; contents.Children.Add(positiveButton); contents.Children.Add(neutralButton); contents.Children.Add(negativeButton); var box = new Microsoft.Phone.Controls.CustomMessageBox() { Caption = title, Message = message, IsLeftButtonEnabled = false, IsRightButtonEnabled = false, Content = contents }; var response = new TaskCompletionSource<ConfirmThreeButtonsResponse>(); positiveButton.Click += (sender, args) => { response.TrySetResult(ConfirmThreeButtonsResponse.Positive); box.Dismiss(); }; neutralButton.Click += (sender, args) => { response.TrySetResult(ConfirmThreeButtonsResponse.Neutral); box.Dismiss(); }; negativeButton.Click += (sender, args) => { response.TrySetResult(ConfirmThreeButtonsResponse.Negative); box.Dismiss(); }; box.Show(); return response.Task; }
private async void ScanButton(object sender, object e) { string result = null; try { Waiter(true); var tcs = new TaskCompletionSource<object>(); StackPanel sp = new StackPanel() { Margin = new Thickness(20) }; #if WINDOWS_PHONE if (Device == null) { Windows.Foundation.Size initialResolution = new Windows.Foundation.Size(640, 480); wbm = new WriteableBitmap(640, 480); Device = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, initialResolution); Device.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, Device.SensorLocation == CameraSensorLocation.Back ? Device.SensorRotationInDegrees : -Device.SensorRotationInDegrees); Device.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Macro); Device.SetProperty(KnownCameraPhotoProperties.SceneMode, CameraSceneMode.Macro); Device.SetProperty(KnownCameraPhotoProperties.FocusIlluminationMode, FocusIlluminationMode.Off); } Rectangle previewRect = new Rectangle() { Height = 480, Width = 360 }; VideoBrush previewVideo = new VideoBrush(); previewVideo.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = (Device.SensorLocation == CameraSensorLocation.Back ? Device.SensorRotationInDegrees : -Device.SensorRotationInDegrees) }; previewVideo.SetSource(Device); previewRect.Fill = previewVideo; Grid combiner = new Grid() { Height = previewRect.Height, Width = previewRect.Width }; combiner.Children.Add(previewRect); Grid.SetColumnSpan(previewRect, 3); Grid.SetRowSpan(previewRect, 3); int windowSize = 100; combiner.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(previewRect.Height / 2 - windowSize) }); combiner.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(windowSize) }); combiner.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(previewRect.Height / 2 - windowSize) }); combiner.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(previewRect.Width / 2 - windowSize) }); combiner.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(windowSize) }); combiner.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(previewRect.Width / 2 - windowSize) }); var maskBrush = new SolidColorBrush(Color.FromArgb(80, 0, 0, 0)); Canvas v1 = new Canvas() { Background = maskBrush }; Canvas v2 = new Canvas() { Background = maskBrush }; Canvas v3 = new Canvas() { Background = maskBrush }; Canvas v4 = new Canvas() { Background = maskBrush }; combiner.Children.Add(v1); Grid.SetRow(v1, 0); Grid.SetColumnSpan(v1, 3); combiner.Children.Add(v2); Grid.SetRow(v2, 2); Grid.SetColumnSpan(v2, 3); combiner.Children.Add(v3); Grid.SetRow(v3, 1); Grid.SetColumn(v3, 0); combiner.Children.Add(v4); Grid.SetRow(v4, 1); Grid.SetColumn(v4, 2); sp.Children.Add(combiner); BackgroundWorker bw = new BackgroundWorker(); DateTime last = DateTime.Now; bw.WorkerSupportsCancellation = true; bw.DoWork += async (s2, e2) => { var reader = new BarcodeReader(); while (!bw.CancellationPending) { if (DateTime.Now.Subtract(last).TotalSeconds > 2) { await Device.FocusAsync(); last = DateTime.Now; } try { Device.GetPreviewBufferArgb(wbm.Pixels); Debug.WriteLine(DateTime.Now.Millisecond); var codeVal = reader.Decode(wbm); if (codeVal != null) { result = codeVal.Text; e2.Cancel = true; tcs.TrySetResult(null); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } }; bw.RunWorkerAsync(); #else var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); if (cameras.Count < 1) { return; } var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras.Last().Id }; var imageSource = new MediaCapture(); await imageSource.InitializeAsync(settings); CaptureElement previewRect = new CaptureElement() { Width = 640, Height = 360 }; previewRect.Source = imageSource; sp.Children.Add(previewRect); await imageSource.StartPreviewAsync(); bool keepGoing = true; Action a = null; a = async () => { if (!keepGoing) return; var stream = new InMemoryRandomAccessStream(); await imageSource.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream); stream.Seek(0); var tmpBmp = new WriteableBitmap(1, 1); await tmpBmp.SetSourceAsync(stream); var writeableBmp = new WriteableBitmap(tmpBmp.PixelWidth, tmpBmp.PixelHeight); stream.Seek(0); await writeableBmp.SetSourceAsync(stream); Result _result = null; var barcodeReader = new BarcodeReader { // TryHarder = true, AutoRotate = true }; try { _result = barcodeReader.Decode(writeableBmp); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } stream.Dispose(); if (_result != null) { result = _result.Text; Debug.WriteLine(_result.Text); keepGoing = false; tcs.TrySetResult(null); } else { var x = RunOnUIThread(a); } }; await RunOnUIThread(a); #endif CustomMessageBox messageBox = new CustomMessageBox() { Title = "Scan Tag", Message = "", Content = sp, LeftButtonContent = "OK", RightButtonContent = "Cancel", IsFullScreen = false, }; messageBox.Unloaded += (s2, e2) => { tcs.TrySetResult(null); }; messageBox.Show(); await tcs.Task; messageBox.Dismiss(); #if WINDOWS_PHONE bw.CancelAsync(); #else keepGoing = false; await imageSource.StopPreviewAsync(); #endif Debug.WriteLine("result: '" + result + "'"); string loc = null; string building = null; string floor = null; string room = null; if (!string.IsNullOrEmpty(result)) { var s = result.Split(new char[] { '?' }, 2); if (s.Length == 2) { var paramList = s[1].Split('&') .Select(p => p.Split(new char[] { '=' }, 2)) .Where(p => p.Length == 2); loc = pick(paramList, "cp"); building = pick(paramList, "bld"); floor = pick(paramList, "flr"); room = pick(paramList, "rm"); } } GeoCoord? locVal = GeoCoord.Parse(loc); if (!string.IsNullOrEmpty(building) && !string.IsNullOrEmpty(floor)) { await ShowMap(RoomInfo.Parse(building + "/" + (room == null ? floor : room)), locVal); } } finally { Waiter(false); } }