diff --git a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml index c3cc6e2c43e..abf88c0e770 100644 --- a/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml +++ b/src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml @@ -1981,6 +1981,14 @@ Foreground="#F5F5F5" IsReadOnly="{TemplateBinding IsReadOnly}" Visibility="Hidden" /> + serializedItems; + private bool isVisibleDropDownTextBlock = false; + + /// + /// This property will Collapse or make Visible the TextBlock for the ComboBox template "RefreshComboBox" (by default will be Collapsed) + /// + public bool IsVisibleDropDownTextBlock + { + get + { + return isVisibleDropDownTextBlock; + } + set + { + isVisibleDropDownTextBlock = value; + RaisePropertyChanged(nameof(IsVisibleDropDownTextBlock)); + } + } /// /// Copy of to be serialized./> diff --git a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/CustomSelection.cs b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/CustomSelection.cs index fe100434466..27e61e99b7a 100644 --- a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/CustomSelection.cs +++ b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/CustomSelection.cs @@ -4,6 +4,10 @@ using System.Windows.Controls; using System.Windows; using Dynamo.Wpf; +using CoreNodeModels; +using System.Windows.Data; +using System.Data.Common; +using System; namespace CoreNodeModelsWpf.Nodes { @@ -12,6 +16,7 @@ namespace CoreNodeModelsWpf.Nodes /// public class CustomSelectionNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization { + private CustomSelectionControl formControl; /// /// Customize the visual appearance of the custom dropdown node. /// @@ -19,7 +24,8 @@ public class CustomSelectionNodeViewCustomization : DropDownNodeViewCustomizatio /// public void CustomizeView(CustomSelection model, NodeView nodeView) { - var formControl = new CustomSelectionControl(new CustomSelectionViewModel(model)); + const double leftMargin = 40; + formControl = new CustomSelectionControl(new CustomSelectionViewModel(model)); nodeView.inputGrid.Children.Add(formControl); @@ -27,12 +33,60 @@ public void CustomizeView(CustomSelection model, NodeView nodeView) base.CustomizeView(model, nodeView); var dropdown = (ComboBox)nodeView.inputGrid.Children[1]; + dropdown.MaxWidth = formControl.Width - leftMargin; formControl.BaseComboBox = dropdown; + formControl.BaseComboBox.SelectionChanged += BaseComboBox_SelectionChanged; // Add margin to the dropdown to show the expander. - dropdown.Margin = new Thickness(40, 0, 0, 0); + dropdown.Margin = new Thickness(leftMargin, 0, 0, 0); dropdown.VerticalAlignment = VerticalAlignment.Top; + dropdown.ApplyTemplate(); + + var dropDownTextBlock = dropdown.Template.FindName("PART_ReadOnlyTextBlock", dropdown) as TextBlock; + if (dropDownTextBlock != null) + { + //IsVisibleDropDownTextBlock will be false by default so the TextBlock (located in the ComboBox template) will be Collapsed then just when is a Custom Selection node we set the value to true and the TextBlock will be visible + //We used a TextBlock because the normal TextBox doesn't have the TextTrimming property and the requirement was asking for setting TextTrimming="CharacterEllipsis" + model.IsVisibleDropDownTextBlock = true; + } + + var dropDownContent = dropdown.Template.FindName("ContentSite", dropdown) as ContentPresenter; + if (dropDownContent != null) + { + dropDownContent.Visibility = Visibility.Collapsed; + } + + // Bind the TextBlock to the selected item hash. + var bindingVal = new Binding(nameof(DSDropDownBase.SelectedString)) + { + Mode = BindingMode.TwoWay, + Source = model + }; + dropDownTextBlock.SetBinding(TextBlock.TextProperty, bindingVal); + } + + private void BaseComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + var comboSender = sender as ComboBox; + if (comboSender != null) + { + comboSender.ToolTip = comboSender.SelectedItem?.ToString(); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected void Dispose(bool disposing) + { + if (disposing) + { + formControl.BaseComboBox.SelectionChanged -= BaseComboBox_SelectionChanged; + } } } -} \ No newline at end of file +}