I'm trying to convert some XAML to C# code. Here's the xaml:
<ComboBox TextBlock.Foreground="{Binding DesiredForegroundBrush}"/>
I'd like to do the same thing in C# code, but I'm at a loss on how to access the TextBlock.
I tried the following:
ComboBoxInstance.TextBlock.SetBinding(TextBlock.ForegroundProperty, "DesiredForegroundBrush");
But the TextBlock is not accessible in C# code.
I also tried getting to the child of the combo box, but the GetChildrenCount returns 0:
var childrenCount = VisualTreeHelper.GetChildrenCount(ComboBoxInstance);
I did a few web searches but all I found was questions about how to bind combo boxes to TextBoxes.
I feel like there has to be an easy way to do this. Any help would be appreciated!
Update:
I have found this post:
How to I access an attached property in code behind?
But that only shows how to directly assign the property in the code behind, as opposed to set up binding on it.