예제 #1
0
        public GraphCreateView(GraphCreatingViewModel model)
        {
            Model = model;

            Model.ObstaclePercentInputMessage = ObstaclePercentInputMsg;
            Model.WidthInputMessage           = WidthInputMsg;
            Model.HeightInputMessage          = HeightInputMsg;
        }
예제 #2
0
        public GraphCreateView(GraphCreatingViewModel model)
        {
            Model = model;
            string graphAssembleMenu = new MenuList(model.GraphAssembleKeys.ToArray(), 1).ToString();

            Model.GraphAssembleInpuMessage    = graphAssembleMenu + ChooseGraphAssemble;
            Model.ObstaclePercentInputMessage = ObstaclePercentInputMsg;
            Model.WidthInputMessage           = WidthInputMsg;
            Model.HeightInputMessage          = HeightInputMsg;
        }
예제 #3
0
        public GraphCreatingWindow(GraphCreatingViewModel model)
        {
            InitializeComponent();

            Model = model;

            okButton.Click     += Model.CreateGraph;
            cancelButton.Click += Model.CancelCreateGraph;


            int ConvertFromString(string str, int alternativeResult)
            {
                return(int.TryParse(str, out int number)
                    ? int.Parse(str)
                    : alternativeResult);
            }

            void StringToWidth(object sender, ConvertEventArgs e)
            {
                var value = ConvertFromString(
                    e.Value.ToString(),
                    Constants.GraphWidthValueRange.LowerValueOfRange);

                value = Constants.GraphWidthValueRange.ReturnInRange(value);

                e.Value = value;
            }

            void StringToHeight(object sender, ConvertEventArgs e)
            {
                var value = ConvertFromString(
                    e.Value.ToString(),
                    Constants.GraphLengthValueRange.LowerValueOfRange);

                value = Constants.GraphLengthValueRange.ReturnInRange(value);

                e.Value = value;
            }

            void IntToString(object sender, ConvertEventArgs e)
            {
                e.Value = e.Value.ToString();
            }

            var bindWidth = new Binding(
                nameof(widthTextBox.Text),
                Model,
                nameof(Model.Width));

            widthTextBox.DataBindings.Add(bindWidth);

            bindWidth.Format += IntToString;
            bindWidth.Parse  += StringToWidth;

            var bindHeight = new Binding(
                nameof(heightTextBox.Text),
                Model,
                nameof(Model.Length));

            heightTextBox.DataBindings.Add(bindHeight);

            bindHeight.Format += IntToString;
            bindHeight.Parse  += StringToHeight;

            var bindTextBoxAndSlider = new Binding(
                nameof(obstacleSlider.Value),
                obstacleTextBox,
                nameof(obstacleTextBox.Text),
                true,
                DataSourceUpdateMode.OnPropertyChanged);

            obstacleSlider.DataBindings.Add(bindTextBoxAndSlider);

            obstacleSlider.Maximum = Constants.ObstaclesPercentValueRange.UpperValueOfRange;
            obstacleSlider.Minimum = Constants.ObstaclesPercentValueRange.LowerValueOfRange;

            var bindObstaclePercent = new Binding(
                nameof(obstacleTextBox.Text),
                Model,
                nameof(Model.ObstaclePercent),
                true,
                DataSourceUpdateMode.OnPropertyChanged);

            obstacleTextBox.DataBindings.Add(bindObstaclePercent);
        }