Example #1
0
        async void OnPageActionSheet(Page sender, ActionSheetArguments options)
        {
            var list = new System.Windows.Controls.ListView
            {
                Style       = (System.Windows.Style)System.Windows.Application.Current.Resources["ActionSheetList"],
                ItemsSource = options.Buttons
            };

            var dialog = new LightContentDialog
            {
                Content = list,
            };

            if (options.Title != null)
            {
                dialog.Title = options.Title;
            }

            list.SelectionChanged += (s, e) =>
            {
                if (list.SelectedItem != null)
                {
                    dialog.Hide();
                    options.SetResult((string)list.SelectedItem);
                }
            };

            /*_page.KeyDown += (window, e) =>
             * {
             *       if (e.Key == System.Windows.Input.Key.Escape)
             *       {
             *               dialog.Hide();
             *               options.SetResult(LightContentDialogResult.None.ToString());
             *       }
             * };*/

            if (options.Cancel != null)
            {
                dialog.IsSecondaryButtonEnabled = true;
                dialog.SecondaryButtonText      = options.Cancel;
            }

            if (options.Destruction != null)
            {
                dialog.IsPrimaryButtonEnabled = true;
                dialog.PrimaryButtonText      = options.Destruction;
            }

            LightContentDialogResult result = await dialog.ShowAsync();

            if (result == LightContentDialogResult.Secondary)
            {
                options.SetResult(options.Cancel);
            }
            else if (result == LightContentDialogResult.Primary)
            {
                options.SetResult(options.Destruction);
            }
        }
Example #2
0
        private bool InternalHide(LightContentDialogResult contentDialogResult)
        {
            LightContentDialogClosingEventArgs lightContentDialogClosingEventArgs = new LightContentDialogClosingEventArgs(contentDialogResult);

            Closing?.Invoke(this, lightContentDialogClosingEventArgs);

            if (!lightContentDialogClosingEventArgs.Cancel && System.Windows.Application.Current.MainWindow is FormsWindow window)
            {
                window.HideContentDialog();
                LightContentDialogClosedEventArgs lightContentDialogClosedEventArgs = new LightContentDialogClosedEventArgs(contentDialogResult);
                Closed?.Invoke(this, lightContentDialogClosedEventArgs);
                return(true);
            }
            return(false);
        }
Example #3
0
        private bool InternalHide(LightContentDialogResult contentDialogResult)
        {
            LightContentDialogClosingEventArgs lightContentDialogClosingEventArgs = new LightContentDialogClosingEventArgs(contentDialogResult);

            Closing?.Invoke(this, lightContentDialogClosingEventArgs);

            if (!lightContentDialogClosingEventArgs.Cancel && (global::Avalonia.Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow is FormsWindow window)
            {
                window.Hide();
                LightContentDialogClosedEventArgs lightContentDialogClosedEventArgs = new LightContentDialogClosedEventArgs(contentDialogResult);
                Closed?.Invoke(this, lightContentDialogClosedEventArgs);
                return(true);
            }
            return(false);
        }
Example #4
0
        public async Task <LightContentDialogResult> ShowAsync()
        {
            if (System.Windows.Application.Current.MainWindow is FormsWindow window)
            {
                window.ShowContentDialog(this);
                LightContentDialogOpenedEventArgs lightContentDialogOpenedEventArgs = new LightContentDialogOpenedEventArgs();
                Opened?.Invoke(this, lightContentDialogOpenedEventArgs);
            }

            LightContentDialogResult contentDialogResult = LightContentDialogResult.None;
            bool exit = false;

            while (!exit)
            {
                tcs = new TaskCompletionSource <LightContentDialogResult>();
                contentDialogResult = await tcs.Task;
                exit = InternalHide(contentDialogResult);
            }

            return(contentDialogResult);
        }
Example #5
0
        //private void OnPrimaryButtonRoutedExecuted(object sender, ExecutedRoutedEventArgs e)
        //{
        //	LightContentDialogButtonClickEventArgs lightContentDialogButtonClickEventArgs = new LightContentDialogButtonClickEventArgs();

        //	PrimaryButtonClick?.Invoke(this, lightContentDialogButtonClickEventArgs);

        //	if (!lightContentDialogButtonClickEventArgs.Cancel)
        //	{
        //		PrimaryButtonCommand?.Execute(PrimaryButtonCommandParameter);
        //		tcs.TrySetResult(LightContentDialogResult.Primary);
        //	}
        //}

        //private void SecondaryButtonRoutedExecuted(object sender, ExecutedRoutedEventArgs e)
        //{
        //	LightContentDialogButtonClickEventArgs lightContentDialogButtonClickEventArgs = new LightContentDialogButtonClickEventArgs();

        //	SecondaryButtonClick?.Invoke(this, lightContentDialogButtonClickEventArgs);

        //	if (!lightContentDialogButtonClickEventArgs.Cancel)
        //	{
        //		SecondaryButtonCommand?.Execute(SecondaryButtonCommandParameter);
        //		tcs.TrySetResult(LightContentDialogResult.Secondary);
        //	}
        //}

        public async Task <LightContentDialogResult> ShowAsync()
        {
            if ((global::Avalonia.Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow is FormsWindow window)
            {
                window.Show();
                LightContentDialogOpenedEventArgs lightContentDialogOpenedEventArgs = new LightContentDialogOpenedEventArgs();
                Opened?.Invoke(this, lightContentDialogOpenedEventArgs);
            }

            LightContentDialogResult contentDialogResult = LightContentDialogResult.None;
            bool exit = false;

            //while (!exit)
            //{
            //	tcs = new TaskCompletionSource<LightContentDialogResult>();
            //	contentDialogResult = await tcs.Task;
            //	exit = InternalHide(contentDialogResult);
            //}

            return(contentDialogResult);
        }
Example #6
0
 public LightContentDialogClosingEventArgs(LightContentDialogResult result)
 {
     Result = result;
 }