locked
GUID & Object reference - Given a GUID how do I access the visual object's attributes? RRS feed

  • Question

  • With the following code I can get the Type and GUID for a visual object that is the child of a given visual object.

    Note:  MyButtonClick is simply used to trigger my test code.

    My goal is to change the background color for the child objects that are of type Border.

    Thanks,


    Steven


    ------------------------------------------------------------------

    private void MyButton_Click(object sender, System.Windows.RoutedEventArgs e)

    {

    Int32 NumberOfChildren;

    Type ChildType;

    Int16 LoopIndex;

    String ChildObjName;

    Guid TempGuid;

    Border TempBorder;

    UIElementCollection ListOfChildren;

    ListOfChildren = SBBGG_Q_AudioPower.Children;

    NumberOfChildren = ListOfChildren.Count;

    for (LoopIndex = 0; LoopIndex < NumberOfChildren; LoopIndex++)

    {

    ChildType = ListOfChildren[LoopIndex].GetType();

    ChildObjName = ChildType.Name; // Same as the line above

    TempGuid = ChildType.GUID;

    }

    }


    ---------------------------------------------------------------------------------------------

    Monday, March 16, 2009 7:00 PM

Answers

  • All I needed to do was to cast the child the object from the Children collection.



    private void MyButton_Click(object sender, System.Windows.RoutedEventArgs e)

    {

        Border border = null;

        foreach (var child in SBBGG_Q_AtHome_Yes.Children)

        {

            if (child is Border)

                {    

                    border = child as Border;

                    border.Background = Brushes.Pink;

                }

            }

        }







    Steven

    Monday, March 16, 2009 9:58 PM