wpf - How can I bind ComboBox.TextBlock in C# -


i'm trying convert xaml c# code. here's xaml:

<combobox textblock.foreground="{binding desiredforegroundbrush}"/> 

i'd same thing in c# code, i'm @ loss on how access textblock.

i tried following:

 comboboxinstance.textblock.setbinding(textblock.foregroundproperty, "desiredforegroundbrush"); 

but textblock not accessible in c# code.

i tried getting child of combo box, getchildrencount returns 0:

 var childrencount = visualtreehelper.getchildrencount(comboboxinstance); 

i did few web searches found questions how bind combo boxes textboxes.

i feel there has easy way this. appreciated!

update:

i have found post:

how access attached property in code behind?

but shows how directly assign property in code behind, opposed set binding on it.

use combobox.foregroundproperty bind foreground color. why want textbox ?


Comments