Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6518 - Cherry Picks for 2.19.5 #15019

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Libraries/CoreNodeModels/DropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ObservableCollection<DynamoDropDownItem> Items
set
{
items = value;
RaisePropertyChanged("Items");
RaisePropertyChanged(nameof(Items));
}
}

Expand Down Expand Up @@ -106,7 +106,6 @@ public int SelectedIndex
selectedString = GetSelectedStringFromItem(Items.ElementAt(value));
}

OnNodeModified();
Copy link
Contributor

@Mikhinja Mikhinja Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the fix for one of those two issues in 3.0 caused an issue in Revit ( REVIT-217658 ) where a custom dropdown node of an internal-package for DynamoRevit that needed to update on idle was stuck always one update state delayed, sometimes leading to confusing situations where Dynamo Player showed content from the previously opened Revit model.

We might want to consider the risks/benefits of this change, and if we will backport this change into 2.19 then in Revit we must also integrate the changes for REVIT-217658. We should also test around nodes that have UI updates to make sure there aren't other issues not yet found.

RaisePropertyChanged("SelectedIndex");
RaisePropertyChanged("SelectedString");
}
Expand Down Expand Up @@ -137,12 +136,12 @@ public string SelectedString
if (item != null)
{
selectedIndex = Items.IndexOf(item);
RaisePropertyChanged("SelectedIndex");
RaisePropertyChanged(nameof(SelectedIndex));
}
}

selectedString = value;
RaisePropertyChanged("SelectedString");
RaisePropertyChanged(nameof(SelectedString));
}
}

Expand Down Expand Up @@ -203,6 +202,8 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
Warning(Dynamo.Properties.Resources.NothingIsSelectedWarning);
}

OnNodeModified();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,70 @@ namespace CoreNodeModelsWpf.Nodes
public class DropDownNodeViewCustomization : INodeViewCustomization<DSDropDownBase>
{
private DSDropDownBase model;
private ComboBox comboBox;

public void CustomizeView(DSDropDownBase model, NodeView nodeView)
{
this.model = model;

//add a drop down list to the window
var combo = new ComboBox
// Add a drop down list to the window
comboBox = new ComboBox
{
Width = System.Double.NaN,
MinWidth= 150,
Width = double.NaN,
MinWidth = 150,
Height = Configurations.PortHeightInPixels,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Center
VerticalAlignment = VerticalAlignment.Center,
Style = (Style)SharedDictionaryManager.DynamoModernDictionary["RefreshComboBox"]
};

nodeView.inputGrid.Children.Add(comboBox);
Grid.SetColumn(comboBox, 0);
Grid.SetRow(comboBox, 0);

combo.Style = (Style)SharedDictionaryManager.DynamoModernDictionary["RefreshComboBox"];
comboBox.DropDownOpened += DropDownOpened;

nodeView.inputGrid.Children.Add(combo);
System.Windows.Controls.Grid.SetColumn(combo, 0);
System.Windows.Controls.Grid.SetRow(combo, 0);
comboBox.DataContext = model;

combo.DropDownOpened += combo_DropDownOpened;

combo.DataContext = model;

// bind this combo box to the selected item hash
var bindingVal = new System.Windows.Data.Binding("Items")
// Bind this combo box to the selected item hash.
var bindingVal = new Binding(nameof(DSDropDownBase.Items))
{
Mode = BindingMode.TwoWay,
Source = model
};
combo.SetBinding(ItemsControl.ItemsSourceProperty, bindingVal);
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, bindingVal);

// bind the selected index to the model property SelectedIndex
var indexBinding = new Binding("SelectedIndex")
// Bind the selected index to the model property SelectedIndex.
var indexBinding = new Binding(nameof(DSDropDownBase.SelectedIndex))
{
Mode = BindingMode.TwoWay,
Source = model
};
combo.SetBinding(Selector.SelectedIndexProperty, indexBinding);
comboBox.SetBinding(Selector.SelectedIndexProperty, indexBinding);

comboBox.SelectionChanged += SelectionChanged;
}

private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBox.SelectedIndex != -1)
{
model.OnNodeModified();
}
}

public void Dispose()
{
comboBox.DropDownOpened -= DropDownOpened;
comboBox.SelectionChanged -= SelectionChanged;
}

/// <summary>
/// When the dropdown is opened, the node's implementation of PopulateItems is called
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void combo_DropDownOpened(object sender, EventArgs e)
void DropDownOpened(object sender, EventArgs e)
{
this.model.PopulateItems();
model.PopulateItems();
}

}
Expand Down
Loading