Пример #1
0
        private double AddBlockToDesignArea(Tuple <string, object> tuple)
        {
            // add block to designer canvas
            var ctText = XamlExporter.GetControlTemplate(tuple.Item2, tuple.Item1);
            var ct     = (ControlTemplate)XamlReader.Parse(ctText);

            var thumb = new Thumb()
            {
                Template = ct
            };

            thumb.DragDelta += (sender, e) =>
            {
                var    t = sender as Thumb;
                double x = Canvas.GetLeft(t) + e.HorizontalChange;
                double y = Canvas.GetTop(t) + e.VerticalChange;
                Canvas.SetLeft(t, x);
                Canvas.SetTop(t, y);
            };

            double blockWidth  = (tuple.Item2 as Canvas).Width;
            double blockHeight = (tuple.Item2 as Canvas).Height;

            Canvas.SetLeft(thumb, CanvasDesignArea.ActualWidth / 2.0 - blockWidth / 2.0);
            Canvas.SetTop(thumb, CanvasDesignArea.ActualHeight / 2.0 - blockHeight / 2.0);

            CanvasDesignArea.Children.Add(thumb);

            return((tuple.Item2 as Canvas).Height);
        }
Пример #2
0
        private void CompileCode()
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            var codeText = TextCode.Text;
            var lines    = BlockParser.SplitText(codeText);
            var commands = BlockParser.ParseLines(lines);

            // commands compiler output
            var output = new StringBuilder();

            output.AppendLine("Count: " + commands.Count().ToString());
            foreach (var c in commands)
            {
                output.AppendLine("");
                output.AppendLine("[Command]");

                foreach (var property in (IDictionary <String, Object>)c)
                {
                    output.AppendLine(property.Key + ": " + property.Value);
                }
            }

            TextOutput.Text = output.ToString();

            // reset canvas
            CanvasDesignArea.Children.Clear();

            var blocks = BlockCompiler.Compile(commands);

            var resourceDictionary = XamlExporter.GetResourceDictionary(blocks);
            var formattedXaml      = XamlExporter.FormatXml(resourceDictionary);

            TextXaml.Text = formattedXaml;

            AddBlocksToDesignArea(blocks);

            sw.Stop();
            System.Diagnostics.Debug.Print("Compiled code in {0}ms", sw.Elapsed.TotalMilliseconds);

            //#if !DEBUG
            //MessageBox.Show("Compiled code in " + sw.Elapsed.TotalMilliseconds.ToString() + "ms");
            //#endif
        }
Пример #3
0
        private void ExportXaml()
        {
            var dlg = new Microsoft.Win32.SaveFileDialog()
            {
                DefaultExt  = "xaml",
                Filter      = "Xaml Files (*.xaml)|*.xaml;|All Files (*.*)|*.*",
                FilterIndex = 1,
                FileName    = "Dictionary1"
            };

            if (dlg.ShowDialog() == true)
            {
                var sw = System.Diagnostics.Stopwatch.StartNew();

                string xamlText = TextXaml.Text;

                XamlExporter.WriteToFile(dlg.FileName, xamlText);

                sw.Stop();
                System.Diagnostics.Debug.Print("Exported xaml in {0}ms", sw.Elapsed.TotalMilliseconds);
            }
        }