コード例 #1
0
        private void BuildUI()
        {
            if (ParamContainer == null)
            {
                return;
            }
            if (ServiceInfo != null && Configuration == null)
            {
                Configuration = new GPConfiguration();
                Configuration.LoadConfiguration(ServiceInfo, ServiceEndpoint);
                return;
            }
            else if (Configuration != null && ServiceEndpoint == null)
            {
                ServiceEndpoint = Configuration.TaskEndPoint;
            }
            paramsScroller.IsEnabled = true;
            if (isLoading)
            {
                ParamContainer.Children.Clear();
                ParamContainer.Children.Add(new TextBlock()
                {
                    Text = ESRI.ArcGIS.Mapping.GP.Resources.Strings.Loading, FontWeight = System.Windows.FontWeights.Bold
                });
            }
            else if (Configuration != null)
            {
                double size = ViewUtility.GetViewHeight() - 325;
                paramsScroller.MaxHeight = size < 100 ? 100 : size;
                size = ViewUtility.GetViewWidth() - 200;
                paramsScroller.MaxWidth = size < 100 ? 100 : size;
                if (paramsScroller.MaxWidth > 500)
                {
                    paramsScroller.MaxWidth = 500;
                }
                ParamContainer.Children.Clear();
                ParamContainer.ColumnDefinitions.Clear();
                ParamContainer.RowDefinitions.Clear();
                ParamContainer.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                ParamContainer.ColumnDefinitions.Add(new ColumnDefinition());// { Width = new GridLength(0, GridUnitType.Star) });
                InputParameters.Clear();

                foreach (ParameterSupport.ParameterConfig config in Configuration.InputParameters)
                {
                    ParameterSupport.ParameterBase parameter = ParameterSupport.ParameterFactory.Create(config, Map);
                    if (parameter != null)
                    {
                        parameter.CanExecuteChanged += parameter_CanExecuteChanged;
                        InputParameters.Add(parameter);
                        if (config.ShownAtRunTime)
                        {
                            ParamContainer.RowDefinitions.Add(new RowDefinition());
                            TextBlock label = new TextBlock()
                            {
                                Text = config.Label,
                                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                Padding           = new Thickness(2, 0, 2, 0)
                            };
                            label.SetValue(Grid.RowProperty, ParamContainer.RowDefinitions.Count - 1);
                            //if (config.Required)
                            //    label.Text += "*";
                            ParamContainer.Children.Add(label);
                            parameter.AddUI(ParamContainer);
                        }
                    }
                }
            }
        }
        public override void AddConfigUI(Grid grid)
        {
            TextBlock label;

            #region Header
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            Grid g = new Grid();
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            label = new TextBlock()
            {
                Text = DisplayName ?? Name,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                Margin            = new Thickness(2),
                FontWeight        = FontWeights.Bold,
                TextTrimming      = TextTrimming.WordEllipsis
            };
            g.Children.Add(label);

            if (Required)
            {
                label = new TextBlock()
                {
                    Text = Resources.Strings.Required,
                    VerticalAlignment   = System.Windows.VerticalAlignment.Center,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
                    Margin     = new Thickness(2),
                    FontWeight = FontWeights.Light,
                    FontStyle  = FontStyles.Italic
                };
                label.SetValue(Grid.ColumnProperty, 1);
                g.Children.Add(label);
            }
            g.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            g.SetValue(Grid.ColumnSpanProperty, 2);
            grid.Children.Add(g);
            #endregion

            #region Type
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            label = new TextBlock()
            {
                Text              = Resources.Strings.LabelType,
                Margin            = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            label = new TextBlock()
            {
                Text              = Type.ToString(),
                Margin            = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            label.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(label);
            #endregion

            #region Label
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            label = new TextBlock()
            {
                Text              = Resources.Strings.LabelLabel,
                Margin            = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            TextBox labelTextBox = new TextBox()
            {
                Text   = Label == null ? string.Empty : Label,
                Margin = new Thickness(2),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            };
            labelTextBox.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            labelTextBox.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(labelTextBox);
            labelTextBox.TextChanged += (s, e) =>
            {
                Label = labelTextBox.Text;
            };
            #endregion

            if (Input)
            {
                #region Tooltip
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelTooltip,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                TextBox tbToolTip = new TextBox()
                {
                    Margin = new Thickness(2),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                };
                if (!string.IsNullOrEmpty(ToolTip))
                {
                    tbToolTip.Text = ToolTip;
                }
                tbToolTip.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tbToolTip.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tbToolTip);
                tbToolTip.TextChanged += (s, e) =>
                {
                    ToolTip = tbToolTip.Text;
                };
                #endregion

                #region Format Tooltip
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelFormatTooltip,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                TextBox tbFormatToolTip = new TextBox()
                {
                    Margin = new Thickness(2),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                };
                if (!string.IsNullOrEmpty(FormatToolTip))
                {
                    tbFormatToolTip.Text = FormatToolTip;
                }
                tbFormatToolTip.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tbFormatToolTip.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tbFormatToolTip);
                tbFormatToolTip.TextChanged += (s, e) =>
                {
                    FormatToolTip = tbFormatToolTip.Text;
                };
                #endregion

                #region ShownAtRuntime
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelShowParameter,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                CheckBox chb = new CheckBox()
                {
                    IsChecked = ShownAtRunTime, Margin = new Thickness(2)
                };
                chb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                chb.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(chb);
                chb.Checked   += (s, e) => { ShownAtRunTime = true; };
                chb.Unchecked += (s, e) => { ShownAtRunTime = false; };
                #endregion

                #region Default Value
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelDefaultValue,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                ParameterBase paramUI = ParameterFactory.Create(this, null);
                paramUI.AddUI(grid);
                paramUI.CanExecuteChanged += (a, b) =>
                {
                    this.DefaultValue = paramUI.Value;
                };
                #endregion
            }
        }