protected override void AddChildItemToVisualTree(object newItem) { if (_useNativeComboBox) { object value = PropertyPathHelper.AccessValueByApplyingPropertyPathIfAny(newItem, DisplayMemberPath); //if (value is UIElement) //{ // SwitchToNonNativeComboBox(); // If the value is a UI element, we should switch to a non-native combo box: //} //else //{ if (value != null) { if (_nativeComboBoxDomElement != null) { var optionDomElement = INTERNAL_HtmlDomManager.AddOptionToNativeComboBox(_nativeComboBoxDomElement, value.ToString()); _itemContainerGenerator.INTERNAL_RegisterContainer(optionDomElement, newItem); } } //todo: else --> ? //} } else { base.AddChildItemToVisualTree(newItem); } }
// Add an empty option at the beginning of the combobox. private void AddEmptyOption() { // Add an empty element that will make it easier to have // nothing selected when items are added to the ComboBox: // See: http://stackoverflow.com/questions/8605516/default-select-option-as-blank var emptyOption = INTERNAL_HtmlDomManager.AddOptionToNativeComboBox(this._nativeComboBoxDomElement, "", 0); CSHTML5.Interop.ExecuteJavaScriptAsync("$0.disabled = true", emptyOption); CSHTML5.Interop.ExecuteJavaScriptAsync("$0.selected = true", emptyOption); CSHTML5.Interop.ExecuteJavaScriptAsync("$0.style.display = 'hidden'", emptyOption); }
private void AddOption(object option, int index) { if (this._nativeComboBoxDomElement == null) { return; } object value = PropertyPathHelper.AccessValueByApplyingPropertyPathIfAny(option, this.DisplayMemberPath); if (value != null) { INTERNAL_HtmlDomManager.AddOptionToNativeComboBox( this._nativeComboBoxDomElement, value.ToString(), index); } }
public override object CreateDomElement(object parentRef, out object domElementWhereToPlaceChildren) { if (_useNativeComboBox) { var select = INTERNAL_HtmlDomManager.CreateDomElementAndAppendIt("select", parentRef, this); domElementWhereToPlaceChildren = select; _nativeComboBoxDomElement = select; INTERNAL_EventsHelper.AttachToDomEvents("change", select, (Action <object>)(e => { DomSelectionChanged(select); })); INTERNAL_HtmlDomManager.SetDomElementStyleProperty(select, new List <string>() { "fontSize" }, "inherit"); // Add an empty element that will make it easier to have nothing selected when items are added to the ComboBox: // See: http://stackoverflow.com/questions/8605516/default-select-option-as-blank var emptyOption = INTERNAL_HtmlDomManager.AddOptionToNativeComboBox(_nativeComboBoxDomElement, ""); CSHTML5.Interop.ExecuteJavaScriptAsync("$0.disabled = true", emptyOption); CSHTML5.Interop.ExecuteJavaScriptAsync("$0.selected = true", emptyOption); CSHTML5.Interop.ExecuteJavaScriptAsync("$0.style.display = 'hidden'", emptyOption); // Set the mark saying that the pointer events must be "absorbed" by the ComboBox: INTERNAL_HtmlDomManager.SetDomElementProperty(select, "data-absorb-events", true); return(select); } else { #if !BRIDGE return(base.CreateDomElement(parentRef, out domElementWhereToPlaceChildren)); #else return(CreateDomElement_WorkaroundBridgeInheritanceBug(parentRef, out domElementWhereToPlaceChildren)); #endif } }