Skip to content

Commit

Permalink
binding issues resolved (#14682)
Browse files Browse the repository at this point in the history
- fixed null exception when trying to assign click handler on a context menu button when the parent button
- also fixed another incorrect binding issue
  • Loading branch information
dnenov authored Feb 1, 2024
1 parent d2e57b5 commit 99cf281
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@
Content="{Binding CanInstall, Converter={StaticResource InstalledButtonTextConverter}}"
DockPanel.Dock="Right"
ToolTipService.ShowOnDisabled="True"
Loaded="DropDownInstallButton_Loaded"
Unloaded="DropDownInstallButton_Unloaded"
IsEnabled="{Binding IsEnabledForInstall}">
<Button.Style>
<Style TargetType="Button">
Expand All @@ -277,7 +279,6 @@
Visibility="{Binding CanInstall, Converter={StaticResource BoolToVisibilityCollapsedConverter}}"
BorderThickness="0"
Cursor="Hand"
Click="DropDownInstallButton_OnClick"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
<Image Source=" /DynamoCoreWpf;component/UI/Images/caret_drop_down.png"
Width="7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,12 @@ private void CloseToastButton_OnClick(object sender, RoutedEventArgs e)
return;
}



private void DropDownInstallButton_OnClick(object sender, RoutedEventArgs e)
{
var button = sender as Button;
if (button == null) { return; }
if (button == null || button.DataContext == null) { return; }

var contextMenu = new ContextMenu();
var commandBinding = new Binding("DownloadLatestToCustomPathCommand");
commandBinding.Source = button.DataContext;
Expand Down Expand Up @@ -187,6 +186,37 @@ private void DropDownInstallButton_OnClick(object sender, RoutedEventArgs e)

// Open the context menu when the left mouse button is pressed
contextMenu.IsOpen = true;
}
}

// Attach the 'context menu' button to the parent button
private void DropDownInstallButton_Loaded(object sender, RoutedEventArgs e)
{
var installButton = sender as Button;
if (installButton != null)
{
var dropDownInstallButton = installButton.Template.FindName("dropDownInstallButton", installButton) as Button;
if (dropDownInstallButton != null)
{
dropDownInstallButton.Click -= DropDownInstallButton_OnClick;

// Now that the parent button is loaded, we can assign the Click event to the context menu button
dropDownInstallButton.Click += DropDownInstallButton_OnClick;
}
}
}

// Dispose of DropDownInstallButton_OnClick when the parent button is unloaded
private void DropDownInstallButton_Unloaded(object sender, RoutedEventArgs e)
{
var installButton = sender as Button;
if (installButton != null)
{
var dropDownInstallButton = installButton.Template.FindName("dropDownInstallButton", installButton) as Button;
if (dropDownInstallButton != null)
{
dropDownInstallButton.Click -= DropDownInstallButton_OnClick;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@
DataContext="{Binding PackageManagerViewModel}"
VerticalAlignment="Stretch"
Height="650"
Visibility="{Binding PackageManagerViewModel.LocalPackages, Converter={StaticResource ListHasMoreThanNItemsToVisibilityConverter}}" />
Visibility="{Binding LocalPackages, Converter={StaticResource ListHasMoreThanNItemsToVisibilityConverter}}" />


<!--Empty list screen-->
<!--Empty list screen-->
<StackPanel Orientation="Vertical"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="0 0 0 73"
Margin="0 127 0 0"
Visibility="{Binding PackageManagerViewModel.LocalPackages, Converter={StaticResource EmptyListToVisibilityConverter }}">
<Image HorizontalAlignment="Center"
VerticalAlignment="Center"
Expand Down

0 comments on commit 99cf281

Please sign in to comment.