public override DataTemplate SelectTemplate(object item, DependencyObject container) { var parent = container; while (parent is not null and not ComboBox and not ComboBoxItem) { parent = VisualTreeHelper.GetParent(parent); } return(parent is ComboBoxItem ? DropdownItemsTemplate ?? DropdownItemsTemplateSelector?.SelectTemplate(item, container) : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { var parent = container; while (parent != null && !(parent is ComboBoxItem) && !(parent is ComboBox)) { parent = VisualTreeHelper.GetParent(parent); } var isInDropdown = (parent is ComboBoxItem); return(isInDropdown ? DropdownItemTemplate ?? DropdownItemTemplateSelector?.SelectTemplate(item, container) : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { //Search up visual tree, stopping at either a ComboBox or a ComboBoxItem (or null). This will determine which template to use while (container != null && !(container is ComboBox) && !(container is ComboBoxItem)) { container = VisualTreeHelper.GetParent(container); } //If you stopped at a ComboBoxItem, you're in the dropdown var inDropDown = container is ComboBoxItem; return(inDropDown ? ItemTemplate ?? ItemTemplateSelector?.SelectTemplate(item, container) : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container)); }
public override DataTemplate?SelectTemplate(object item, DependencyObject container) { var parent = container; // Search up the visual tree, stopping at either a ComboBox or // a ComboBoxItem (or null). This will determine which template to use while (parent != null && parent is not ComboBoxItem && parent is not ComboBox) { parent = VisualTreeHelper.GetParent(parent); } // If you stopped at a ComboBoxItem, you're in the dropdown var inDropDown = parent is ComboBoxItem; return(inDropDown ? DropdownItemsTemplate ?? DropdownItemsTemplateSelector?.SelectTemplate(item, container) : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { DependencyObject itemToCheck = container; // Search up the visual tree, stopping at either a ComboBox or // a ComboBoxItem (or null). This will determine which template to use while (itemToCheck != null && !(itemToCheck is ComboBoxItem) && !(itemToCheck is ComboBox)) { itemToCheck = VisualTreeHelper.GetParent(itemToCheck); } // If you stopped at a ComboBoxItem, you're in the dropdown bool inDropDown = itemToCheck is ComboBoxItem; return(inDropDown ? DropdownItemsTemplate ?? DropdownItemsTemplateSelector?.SelectTemplate(item, container) : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container)); }
private View CreateSelectedItem(object item) { View selectedItemView = null; if (SelectedItemTemplateSelector != null) { DataTemplate actualTemplate = SelectedItemTemplateSelector.SelectTemplate(item, null); selectedItemView = SelectedItemTemplate.CreateContent() as View; } else if (SelectedItemTemplate != null) { selectedItemView = SelectedItemTemplate.CreateContent() as View; } else { throw new Exception("DropDown SelectedItemTemplateSelector and SelectedItemTemplate is null!"); } return(selectedItemView); }