Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have resolved this issue with a different way.<br> ComboBox SelectedItem is not what it displays but is what you select. When you select an Item comboBox takes the ComboBox displays it in SelectionBox's Template not in SelectedItem,s Template. If you will go into VisualTree of ComboBox, you will see that it has a ContentPresenter that contains a TextBlock and this TextBlock is assigned with the text of selected item.<br> So what i did, in SelectionChanged event handler i looked for the TextBlock inside that ContentPresenter using VisualTreeHelper and then i Binded the Text property of this TextBlock to the Content property of my ContentControl(SelectedItem).</p> <h3>Edit:</h3> <p>In the SelectionChanged evetn handler of ComboBox I wrote:</p> <pre><code>ModifyCombox(cmbAnimationBlocks, myComboBox.SelectedItem.As&lt;ContentControl&gt;()); </code></pre> <p>and this method is:</p> <pre><code> private static void ModifyCombox(DependencyObject comboBox, ContentControl obj) { if (VisualTreeHelper.GetChildrenCount(comboBox) &gt; 0) { WalkThroughElement(comboBox, obj); } } private static void WalkThroughElement(DependencyObject element, ContentControl contentControl) { for (int i = 0; i &lt; VisualTreeHelper.GetChildrenCount(element); i++) { if (element.GetType() == typeof(ContentPresenter)) { ContentPresenter contentPresenter = element.As&lt;ContentPresenter&gt;(); TextBlock textBlock = VisualTreeHelper.GetChild(contentPresenter, 0).As&lt;TextBlock&gt;(); textBlock.SetBinding(TextBlock.TextProperty, new Binding("Content") { Source = contentControl }); contentPresenter.Content = textBlock; } else { DependencyObject child = VisualTreeHelper.GetChild(element, i).As&lt;FrameworkElement&gt;(); WalkThroughElement(child, contentControl); } } if (VisualTreeHelper.GetChildrenCount(element) == 0 &amp;&amp; element.GetType() == typeof(ContentPresenter)) { ContentPresenter contentPresenter = element.As&lt;ContentPresenter&gt;(); TextBlock textBlock = new TextBlock(); textBlock.SetBinding(TextBlock.TextProperty, new Binding("Content") { Source = contentControl }); contentPresenter.Content = textBlock; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload