Skip to content

Commit

Permalink
DYN-6440 Custom Selection node overlapping Code Review
Browse files Browse the repository at this point in the history
Added more comments for clarifying the use of the IsVisibleDropDownTextBlock  property.
Also I've added the Dispose() method for unsubscribing event handlers (although I'm not so sure if we are disposing this class correctly).
  • Loading branch information
RobertGlobant20 committed Feb 23, 2024
1 parent 3b3b57c commit c08ab0e
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Dynamo.Wpf;
using CoreNodeModels;
using System.Windows.Data;
using System.Data.Common;
using System;

namespace CoreNodeModelsWpf.Nodes
{
Expand All @@ -14,6 +16,7 @@ namespace CoreNodeModelsWpf.Nodes
/// </summary>
public class CustomSelectionNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization<CustomSelection>
{
private CustomSelectionControl formControl;
/// <summary>
/// Customize the visual appearance of the custom dropdown node.
/// </summary>
Expand All @@ -22,7 +25,7 @@ public class CustomSelectionNodeViewCustomization : DropDownNodeViewCustomizatio
public void CustomizeView(CustomSelection model, NodeView nodeView)
{
const double leftMargin = 40;
var formControl = new CustomSelectionControl(new CustomSelectionViewModel(model));
formControl = new CustomSelectionControl(new CustomSelectionViewModel(model));

nodeView.inputGrid.Children.Add(formControl);

Expand All @@ -43,6 +46,8 @@ public void CustomizeView(CustomSelection model, NodeView nodeView)
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;
}

Expand All @@ -69,5 +74,19 @@ private void BaseComboBox_SelectionChanged(object sender, SelectionChangedEventA
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;
}
}
}
}

0 comments on commit c08ab0e

Please sign in to comment.