2011-11-07 3 views
0

J'essaie d'effectuer une liaison bidirectionnelle par exemple j'ai un bouton (sur de nombreuses commandes), sur sa sélection, je montre les valeurs de ses propriétés diff (comme la hauteur, la largeur etc) dans certains textinput. Ce processus à sens unique fonctionne bien.Comment gérer l'événement pour les objets non visuels dans Flex

Mais le processus inverse ne fonctionne pas. i.e Lorsque je sélectionne un bouton, et que j'essaie de changer sa dimension en entrant une valeur en hauteur, width textinputs, les dimensions ne sont pas modifiées.

Comment savoir quel bouton a été sélectionné par moi? Comment les événements doivent-ils être traités ici? membre


private void Form1_Load(object sender, System.EventArgs e) 
     { 
      //Create some data and bind it to the grid 
      dt1 = GetData(1000, 3); 
      this.UltraGrid1.DataSource = dt1; 
      //Set the grid's CreationFilter to a new instance of the NumbersInRowSelectors class. 
      this.UltraGrid1.CreationFilter = new NumbersInRowSelectors();   
     } 

     private void UltraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) 
     {  
      //Hide the default images that are drawn in the RowSelectors, like the pencil and asterisk, etc. 
      e.Layout.Override.RowSelectorAppearance.ImageAlpha = Infragistics.Win.Alpha.Transparent; 

      //Center the text in the RowSelectors. 
      e.Layout.Override.RowSelectorAppearance.TextHAlign = Infragistics.Win.HAlign.Center; 
      e.Layout.Override.RowSelectorAppearance.TextVAlign = Infragistics.Win.VAlign.Middle;   

      //There is no wy to change the width of the RowSelectors. 
      //Use a smaller font, so that 3-digit numbers will fit. 
      e.Layout.Override.RowSelectorAppearance.FontData.Name = "Small Fonts"; 
      e.Layout.Override.RowSelectorAppearance.FontData.SizeInPoints = 6; 
     } 

     //The NumbersInRowSelectors class. This class Implements a CreationFilter and 
     //adds a TextUIElement to each RowSelector which displays the row number of 
     //the row. 
     public class NumbersInRowSelectors:Infragistics.Win.IUIElementCreationFilter 
     { 

      #region Implementation of IUIElementCreationFilter 
      public void AfterCreateChildElements(Infragistics.Win.UIElement parent) 
      { 
       //Don't need to do anything here 
      } 
      public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent) 
      { 
       //Declare some variables 
       Infragistics.Win.TextUIElement objTextUIElement; 
       Infragistics.Win.UltraWinGrid.RowSelectorUIElement objRowSelectorUIElement; 
       Infragistics.Win.UltraWinGrid.UltraGridRow objRow; 
       int RowNumber; 

       //Check to see if the parent is a RowSelectorUIElement. If not, 
       //we don't need to do anything 
       if (parent is Infragistics.Win.UltraWinGrid.RowSelectorUIElement) 
       { 
        //Get the Row from the RowSelectorsUIElement 
        objRowSelectorUIElement = (Infragistics.Win.UltraWinGrid.RowSelectorUIElement)parent; 
        objRow = (Infragistics.Win.UltraWinGrid.UltraGridRow)objRowSelectorUIElement.GetContext(typeof(Infragistics.Win.UltraWinGrid.UltraGridRow)); 

        //Get the Index of the Row, so we can use it as a row number. 
        RowNumber = objRow.Index; 

        //Check to see if the TextUIElement is already created. Since 
        //The RowSelectorsUIElement never has children by default, we 
        //can just check the count. 
        if (parent.ChildElements.Count == 0) 
        { 
         //Create a new TextUIElement and parent it to the RowSelectorUIElement 
         objTextUIElement = new Infragistics.Win.TextUIElement(parent, RowNumber.ToString()); 
         parent.ChildElements.Add(objTextUIElement); 
        } 
        else 
        { 
         //There's already a TextUIElement here, so just set the Text 
         objTextUIElement = (Infragistics.Win.TextUIElement)parent.ChildElements[0]; 
         objTextUIElement.Text = RowNumber.ToString(); 
        } 
        //Position the TextUIElement into the RowSelectorUIElement 
        objTextUIElement.Rect = parent.RectInsideBorders; 

        //Return True let the grid know we handled this event. 
        //This doesn't really do anything, since the grid 
        //does not create any child elements for this object, anyway. 
        return true; 
       } 

       //Return false to let the grid know we did not handle the event. 
       //This doesn't really do anything, since the grid 
       //does not create any child elements for this object, anyway. 
       return false;    
      }  
      #endregion 
     } 

    } 
+3

Pouvez-vous poster le code du composant avec les textinputs que vous popping lorsque le bouton est sélectionné? Cela rendrait plus facile de vous donner un code spécifique. –

+0

Je pense que vous aviez manqué quelque chose que vous avez posté une question non visuelle mais vous avez donné le bouton (une composante visuelle). poster un exemple de code est facile à aider – Exhausted

Répondre

0

Créer un « élément sélectionné » dans la classe où le bouton et l'édition de texte sont déclarés.

Dans l'écouteur d'événement de sélection de bouton, affectez la cible d'événement à ce membre. Ensuite, utilisez-le dans l'écouteur d'événement d'édition de texte. Par exemple:

// It's a declaration of the member variable 
private var m_current_btn:Button = null; 

// It's an event listener for your button 
private function on_selection_change(event:Event):void 
{ 
    m_current_btn = event.target as Button; 
    // button_x and button_y are two text edits 
    button_x.text = m_current_button.x.toString(); 
    button_y.text = m_current_button.y.toString(); 
} 

// Event listener to track changes in the coordinate text inputs 
private function on_coordinate_textedit_change(event:Event):void 
{ 
    if (m_current_btn != null) 
    { 
    m_current_btn.x = parseInt(button_x.text); 
    m_current_btn.y = parseInt(button_y.text); 
    } 
} 
Questions connexes