private void OnSegmentSelected(object sender, SegmentedControlEventArgs e)
        {
            if (sender is SegmentedControl control)
            {
                switch (e.Segment.Text)
                {
                case "Orange":
                    control.SelectedBackgroundColor = Color.Orange;
                    control.SelectedTextColor       = Color.Default;
                    break;

                case "Blue":
                    control.SelectedBackgroundColor = Color.Blue;
                    control.SelectedTextColor       = Color.White;
                    break;

                case "Yellow":
                    control.SelectedBackgroundColor = Color.Yellow;
                    control.SelectedTextColor       = Color.Default;
                    break;
                }
            }
        }
示例#2
0
        async void OnDestinationSelector_SegmentTapped(object sender, SegmentedControlEventArgs e)
        {
            if (_processing)
            {
                return;
            }
            _processing = true;

            if (e.Segment.Text.Contains("PNG") && await Forms9Patch.ToPngService.ToPngAsync(_htmlEditor.Text, "myHtmlPage") is ToFileResult pngResult)
            {
                if (pngResult.IsError)
                {
                    using (Forms9Patch.Toast.Create("PNG error", pngResult.Result)) { }
                }
                else
                {
                    var entry = new Forms9Patch.MimeItemCollection();
                    entry.AddBytesFromFile("image/png", pngResult.Result);

                    if (e.Segment.Text.Contains("SHARE"))
                    {
                        Forms9Patch.Sharing.Share(entry, _destinationSelector);
                    }
                    else
                    {
                        Forms9Patch.Clipboard.Entry = entry;
                    }
                }
            }
            else if (e.Segment.Text.Contains("PDF"))
            {
                if (Device.RuntimePlatform == Device.UWP)
                {
                    using (Forms9Patch.Toast.Create("PDF export not available in UWP", "However, you can print to PDFs!  So, try <b>Print</b> and then select <b>Microsoft Print to PDF</b> as your printer.")) { }
                }
                else if (await Forms9Patch.ToPdfService.ToPdfAsync(_htmlEditor.Text, "myHtmlPage") is ToFileResult pdfResult)
                {
                    if (pdfResult.IsError)
                    {
                        using (Forms9Patch.Toast.Create("PDF error", pdfResult.Result)) { }
                    }
                    else
                    {
                        var entry = new Forms9Patch.MimeItemCollection();
                        entry.AddBytesFromFile("application/pdf", pdfResult.Result);

                        if (e.Segment.Text.Contains("SHARE"))
                        {
                            Forms9Patch.Sharing.Share(entry, _destinationSelector);
                        }
                        else
                        {
                            Forms9Patch.Clipboard.Entry = entry;
                        }
                    }
                }
            }
            else if (e.Segment.Text.Contains("PRINT"))
            {
                Forms9Patch.PrintService.Print(_htmlEditor.Text, "myHtmlPage");
            }
            _processing = false;
        }