Пример #1
0
        public MainWindow() : base(new[]
        {
            "resm:OxyPlot.Avalonia.Themes.Default.xaml?assembly=OxyPlot.Avalonia"
        })
        {
            var grRoot = new Grid()
            {
                DataContext = m, Margin = new Thickness(10)
            };

            grRoot.RowDefinitions.Add(new RowDefinition(1, GridUnitType.Auto));
            grRoot.RowDefinitions.Add(new RowDefinition(1, GridUnitType.Star));
            grRoot.RowDefinitions.Add(new RowDefinition(100, GridUnitType.Pixel));

            pv       = new PlotView();
            pv.Model = new PlotModel();
            Grid.SetRow(pv, 1);
            grRoot.Children.Add(pv);

            var grSplit = new GridSplitter()
            {
                Height = 10, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top
            };

            Grid.SetRow(grSplit, 2);
            grRoot.Children.Add(grSplit);

            tboxLog = new TextBox()
            {
                Margin = new Thickness(0, 20, 0, 0)
            };
            Grid.SetRow(tboxLog, 2);
            grRoot.Children.Add(tboxLog);

            var durationConverter        = new QuantityConverter((s, c) => Duration.Parse(s, c));
            var rotationalSpeedConverter = new QuantityConverter((s, c) => RotationalSpeed.Parse(s, c));

            {
                var sp = new StackPanel()
                {
                    Orientation = Avalonia.Layout.Orientation.Vertical
                };

                Func <string, TextBlock> tblkField = (s) =>
                                                     new TextBlock
                {
                    Text = s,
                    VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
                    FontWeight        = FontWeight.Bold,
                    Margin            = new Thickness(10, 0, 0, 0)
                };

                Func <string, IValueConverter, TextBox> tboxField = (propname, cvt) =>
                {
                    var tbox = new TextBox {
                        MinWidth = 100, Margin = new Thickness(10, 0, 0, 0)
                    };
                    tbox[!TextBox.TextProperty] = new Binding(propname)
                    {
                        Mode = BindingMode.TwoWay, Converter = cvt
                    };
                    return(tbox);
                };


                {
                    var spH = new StackPanel()
                    {
                        Orientation = Avalonia.Layout.Orientation.Horizontal
                    };
                    sp.Children.Add(spH);

                    TextBox durationTbox = null;
                    spH.Children.Add(tblkField("Duration").Eval((tblk) => { tblk.Margin = new Thickness(); return(tblk); }));
                    spH.Children.Add(durationTbox = tboxField("Duration", durationConverter));

                    var sld = new Slider()
                    {
                        Width       = 200,
                        Minimum     = 0.5,
                        Maximum     = 10,
                        LargeChange = 0.5,
                        SmallChange = 0.5,
                        Value       = m.Duration.Seconds
                    };
                    sld.PropertyChanged += (a, b) =>
                    {
                        if (b.Property.Name == "Value")
                        {
                            var prev = m.Duration.Seconds;
                            var next = sld.Value.MRound(0.5);
                            if (prev != next)
                            {
                                m.Duration        = Duration.FromSeconds(next);
                                durationTbox.Text = m.Duration.ToString();
                                Recompute();
                            }
                        }
                    };
                    spH.Children.Add(sld);

                    spH.Children.Add(tblkField("TargetSpeed"));
                    spH.Children.Add(tboxField("TargetSpeed", rotationalSpeedConverter));

                    spH.Children.Add(tblkField("RenderPts"));
                    spH.Children.Add(tboxField("RenderPts", null));
                }

                {
                    sp.Children.Add(new TextBlock()
                    {
                        Text   = "plot mouse LEFT:(show value) - WHEEL:(zoom 1clk=rect-zoom 2clk=fit) - RIGHT:pan",
                        Margin = new Thickness(0, 10, 0, 0)
                    });
                }

                var btnRefresh = new Button()
                {
                    Content = "Refresh"
                };
                btnRefresh.Click += (a, b) =>
                {
                    Recompute();
                };
                sp.Children.Add(btnRefresh);

                Grid.SetRow(sp, 0);
                grRoot.Children.Add(sp);
            }

            {
                Recompute();
                pv.ResetAllAxes();
                pv.InvalidatePlot();
            }

            this.Content = grRoot;
        }