Select to view content in your preferred language

forms (not FeatureDataForm) - unable 2 bind from graphic from code behind

789
0
12-07-2012 01:36 PM
Ravichandran_M_Kaushika
Regular Contributor
dear Readers,

thanks a lot for taking the read the post. we are unable to use featuredata form from esri in our app for the following reasons:

1. users want the columns to be listed in different tabs based on the info they contain, the feature data layer has 96 columns (yes 96)

2. support tables should be modifiable (could not do it sde domain tables), and

3. we realized something later than more than 1 value is valid for some of the columns in a feature layer driven by attribute support tables.

so a new user control was created with some tabs to hold functional column/fields together. inside each of the tab, there was a named stackpanel that contained a grid to hold all columns and their labels. since there were 96, we opted to create those fields from code behind to control the style and be consistent.

in the codebehind, we were binding the textboxes (trying to get text boxes to display the selected feature's attribute data 1st - later on single select combo box to match up to attribute values in feature data layer - not to speak about multi-select controls now) . these values were to come from the selected graphics in the mainpage. the controls are in the ucDamsAttributes.XAML.

once the user selects a graphic, the datacontext in the ucDamsAttributes page is 'set'. as shown below.
  
 void featLayer4Editing_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
        {
            e.Handled = true;
            if (e.Graphic.Geometry is MapPoint)
            {
                e.Graphic.Selected = true;
                _GrphcLastGraphic = e.Graphic;
                fdgFeatDataGrid4EditableLayer.ScrollIntoView(e.Graphic, null);
               _ucDamsLayer.DataContext = fdgFeatDataGrid4EditableLayer.GraphicsLayer.Graphics[0].Attributes;              
  //_ucDamsLayer.DataContext = fdgFeatDataGrid4EditableLayer.GraphicsLayer;
  //  _ucDamsLayer.DataContext = e.Graphic.Attributes;
            }
        }


the commented versions and the uncommented version did not send the data to the text boxes, although every time, ucPanels datacontext  was able to display the 96 odd keys and 96 odd values. but when the binding was set, nothing happened.

      Binding bBinding = new Binding();
            bBinding.Mode = BindingMode.TwoWay;
            bBinding.Source = this.DataContext;
            if (this.DataContext != null && objDataEntryGrid.DataContext ==null)
            {
                objDataEntryGrid.DataContext= this.DataContext;
            }
             //objDataEntryGrid is the grid for arranging the location of the labels, fields etc

            PropertyPath ppPath4Binding = new PropertyPath(strBindingPathColumnName);
            bBinding.Path = ppPath4Binding;
            tbTextBox2BAdded.SetBinding(TextBox.TextProperty, bBinding);


strBindingPathCOlumnName is a parameter to a function that contains the above code snippet. the function will be pasted below. strBindingPathColumnName is the actual column name inthe feature layer that should tie the textboxt.text display to the value of the selected graphic.

 void LoadTextBoxControlAndTextLabel(string strTextBlockLabel4ControlInParam,
                                            string strControlNameInParam,
                                            StackPanel StackPanel2BProcessed,
                                            double dblTextBoxWidth,
                                            int intTextBoxMaxLength,
                                            string strTextBoxHelperMsg,
                                            string strToolTipMsg,
                                            string strBindingPathColumnName
                                            )
        {
            Grid objDataEntryGrid = (Grid)StackPanel2BProcessed.Children[0];
            RowDefinition objRD = new RowDefinition();
            objDataEntryGrid.RowDefinitions.Add(objRD);
            int intTargetRow4Add = (objDataEntryGrid.RowDefinitions.Count - 1);
            Thickness thickness4Control = SetUniformWidthMarginForDataEntryControls(4);
            //add textblock
            TextBlock txtBlock2BAdded = new TextBlock();
            txtBlock2BAdded = ReturnQualifiedTextBlockWithNamesLabels(strTextBlockLabel4ControlInParam,
                                                strControlNameInParam,
                                                intTargetRow4Add,
                                                thickness4Control);
            if (!(System.String.IsNullOrEmpty(strToolTipMsg)))
                ToolTipService.SetToolTip(txtBlock2BAdded, strToolTipMsg);
            objDataEntryGrid.Children.Add(txtBlock2BAdded);
            //add textbox
            TextBox tbTextBox2BAdded = new TextBox();
            tbTextBox2BAdded.Name = "textBox4" + strControlNameInParam;
            tbTextBox2BAdded.Margin = thickness4Control;
            tbTextBox2BAdded.Width = dblTextBoxWidth;
            tbTextBox2BAdded.MaxLength = intTextBoxMaxLength;
            tbTextBox2BAdded.SetValue(Grid.ColumnProperty, 1);
            tbTextBox2BAdded.SetValue(Grid.RowProperty, intTargetRow4Add);
            //tbTextBox2BAdded.DataContext = this.DataContext;
            
            Binding bBinding = new Binding();
            bBinding.Mode = BindingMode.TwoWay;
            bBinding.Source = this.DataContext;
            if (this.DataContext != null && objDataEntryGrid.DataContext ==null)
            {
                objDataEntryGrid.DataContext= this.DataContext;
            }
            
   PropertyPath ppPath4Binding = new PropertyPath(strBindingPathColumnName);
            bBinding.Path = ppPath4Binding;
            tbTextBox2BAdded.SetBinding(TextBox.TextProperty, bBinding);

            objDataEntryGrid.Children.Add(tbTextBox2BAdded);
            if (!(System.String.IsNullOrEmpty(strTextBoxHelperMsg)))
            {
                //add textblock for helper message
                ........ //code of not interest to our question.
            }
        }


this function is called from another LoadControl2ThisStackPanelOrTab like this:

 
//NID ID
            LoadTextBoxControlAndTextLabel("NID ID:", "NIDID", stkPnl4IdentifierTab, 150, 50, "", "Tooltip message...", "NID_ID");
          


Need suggestions and advise.

thank you for your time.

regards
ravi.
0 Kudos
0 Replies