private void RefreshStylesAfterExternalEvent() { var panel = m_Panel.visualTree.elementPanel; if (panel == null) { return; } var updater = panel.GetUpdater(VisualTreeUpdatePhase.Bindings) as VisualTreeBindingsUpdater; if (updater == null) { return; } updater.PollElementsWithBindings((e, b) => BindingExtensions.HandleStyleUpdate(e)); }
void BindListViewItem(VisualElement ve, int index) { var field = ve as IBindable; if (field == null) { //we find the first Bindable field = ve.Query().Where(x => x is IBindable).First() as IBindable; } if (field == null) { //can't default bind to anything! throw new InvalidOperationException("Can't find BindableElement: please provide BindableVisualElements or provide your own Listview.bindItem callback"); } object item = listView.itemsSource[index]; var itemProp = item as SerializedProperty; field.bindingPath = itemProp.propertyPath; BindingExtensions.Bind(ve, boundObject, itemProp); }
void Reset(SerializedProperty property) { m_SerializedProperty = property; if (m_SerializedProperty != null && m_SerializedProperty.isValid) { // if we already have a serialized property, determine if the property field can be reused without reset // this is only supported for non propertydrawer types if (m_ChildField != null && m_SerializedProperty.propertyType == property.propertyType) { var newField = CreateOrUpdateFieldFromProperty(property, m_ChildField); // there was an issue where we weren't able to swap the bindings on the original field if (newField != m_ChildField) { m_ChildField.Unbind(); var childIndex = IndexOf(m_ChildField); if (childIndex >= 0) { m_ChildField.RemoveFromHierarchy(); m_ChildField = newField; hierarchy.Insert(childIndex, m_ChildField); } } return; } } Clear(); m_ChildField?.Unbind(); m_ChildField = null; if (property == null) { return; } ComputeNestingLevel(); VisualElement customPropertyGUI = null; // Case 1292133: set proper nesting level before calling CreatePropertyGUI var handler = ScriptAttributeUtility.GetHandler(m_SerializedProperty); using (var nestingContext = handler.ApplyNestingContext(m_DrawNestingLevel)) { if (handler.hasPropertyDrawer) { customPropertyGUI = handler.propertyDrawer.CreatePropertyGUI(m_SerializedProperty); if (customPropertyGUI == null) { customPropertyGUI = CreatePropertyIMGUIContainer(); } else { RegisterPropertyChangesOnCustomDrawerElement(customPropertyGUI); } } else { customPropertyGUI = CreateOrUpdateFieldFromProperty(m_SerializedProperty); m_ChildField = customPropertyGUI; } } if (customPropertyGUI != null) { PropagateNestingLevel(customPropertyGUI); hierarchy.Add(customPropertyGUI); } if (m_SerializedProperty.propertyType == SerializedPropertyType.ManagedReference) { BindingExtensions.TrackPropertyValue(this, m_SerializedProperty, Reset); } }