Пример #1
0
        private void GraphMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
        {
            var dataPackage = new DataPackage();

            dataPackage.RequestedOperation = DataPackageOperation.Copy;

            var bitmapStream = GraphingControl.GetGraphBitmapStream();

            dataPackage.SetBitmap(bitmapStream);
            Clipboard.SetContent(dataPackage);
        }
Пример #2
0
        // When share is invoked (by the user or programmatically) the event handler we registered will be called to populate the data package with the
        // data to be shared. We will request the current graph image from the grapher as a stream that will pass to the share request.
        private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var resourceLoader = ResourceLoader.GetForCurrentView();

            try
            {
                string rawHtml;
                string equationHtml;

                rawHtml = "<p><img src='graph.png' width='600' alt='" + resourceLoader.GetString("GraphImageAltText") + "'></p>";

                var  equations    = ViewModel.Equations;
                bool hasEquations = false;

                if (equations.Count > 0)
                {
                    equationHtml = "<span style=\"color: rgb(68, 114, 196); font-style: bold; font-size : 13pt;\">"
                                   + resourceLoader.GetString("EquationsShareHeader") + "</span>"
                                   + "<table cellpadding=\"0\" cellspacing=\"0\" >";

                    foreach (var equation in equations)
                    {
                        var expression = equation.Expression;
                        if (string.IsNullOrEmpty(expression))
                        {
                            continue;
                        }

                        var color = equation.LineColor;
                        hasEquations = true;

                        expression = GraphingControl.ConvertToLinear(expression);

                        string equationColorHtml;
                        equationColorHtml = "color:rgb(" + color.R.ToString() + "," + color.G.ToString() + "," + color.B.ToString() + ");";

                        equationHtml += "<tr style=\"margin: 0pt 0pt 0pt 0pt; padding: 0pt 0pt 0pt 0pt; \"><td><span style=\"font-size: 22pt; line-height: 0;"
                                        + equationColorHtml + "\">&#x25A0;</span></td><td><div style=\"margin: 4pt 0pt 0pt 6pt;\">"
                                        + Utilities.EscapeHtmlSpecialCharacters(expression) + "</div></td>";
                    }
                    equationHtml += "</table>";

                    if (hasEquations)
                    {
                        rawHtml += equationHtml;
                    }
                }

                var variables = ViewModel.Variables;

                if (variables.Count > 0)
                {
                    var localizedSeperator = LocalizationSettings.GetInstance().GetListSeparatorWinRT() + " ";

                    rawHtml += "<br><span style=\"color: rgb(68, 114, 196); font-style: bold; font-size: 13pt;\">"
                               + resourceLoader.GetString("VariablesShareHeader")
                               + "</span><br><div style=\"margin: 4pt 0pt 0pt 0pt;\">";

                    for (int i = 0; i < variables.Count; i++)
                    {
                        var name  = variables[i].Name;
                        var value = variables[i].Value;

                        rawHtml += name + "=";
                        var formattedValue = value.ToString();
                        rawHtml += formattedValue;

                        if (variables.Count - 1 != i)
                        {
                            rawHtml += localizedSeperator;
                        }
                    }

                    rawHtml += "</div>";
                }

                rawHtml += "<br><br>";

                // Shortcut to the request data
                var requestData = args.Request.Data;

                DataPackage dataPackage = new DataPackage();
                var         html        = HtmlFormatHelper.CreateHtmlFormat(rawHtml);

                requestData.Properties.Title = resourceLoader.GetString("ShareActionTitle");

                requestData.SetHtmlFormat(html);

                var bitmapStream = GraphingControl.GetGraphBitmapStream();

                requestData.ResourceMap.Add("graph.png", bitmapStream);
                requestData.SetBitmap(bitmapStream);

                // Set the thumbnail image (in case the share target can't handle HTML)
                requestData.Properties.Thumbnail = bitmapStream;
            }
            catch (Exception ex)
            {
                ShowShareError();
                CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogPlatformExceptionInfo(ViewMode.Graphing, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message, ex.HResult);
            }
        }