As a proof-of-concept, I created an application that simply displays a
ComboBoxthat displays the available columns. The user can select a column and press the "Update" button. When the "Update" button is selected, the
ComboBoxwill move to the selected column. The application looks like the following (I know it's ugly, but I've also been playing with some of the
The XAML code that is of interest looks like the following (please bear in mind this is just a snippet and not the whole thing):
The Attached Properties in the code snipped used above are
Grid.Column. These properties define where in the grid the
ComboBoxis displayed. In order to set the attached property from the code behind, I had to essentially use 1 (yes one) line of code in the Click event of the Button. That line of code looks like the following:
selectedIndex is just an integer set from the selected value of the combo box.
The "magic" occurs because Attached Properties essentially call static methods of an object. The static method is always named in the same manner. It is defined as
ObjectType.SetNameOfProperty. So from the example, the
Column. Pretty kewl.