Skip to content

Commit 99cf281

Browse files
authored
binding issues resolved (#14682)
- fixed null exception when trying to assign click handler on a context menu button when the parent button - also fixed another incorrect binding issue
1 parent d2e57b5 commit 99cf281

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

src/DynamoCoreWpf/Views/PackageManager/Controls/PackageManagerPackagesControl.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@
256256
Content="{Binding CanInstall, Converter={StaticResource InstalledButtonTextConverter}}"
257257
DockPanel.Dock="Right"
258258
ToolTipService.ShowOnDisabled="True"
259+
Loaded="DropDownInstallButton_Loaded"
260+
Unloaded="DropDownInstallButton_Unloaded"
259261
IsEnabled="{Binding IsEnabledForInstall}">
260262
<Button.Style>
261263
<Style TargetType="Button">
@@ -277,7 +279,6 @@
277279
Visibility="{Binding CanInstall, Converter={StaticResource BoolToVisibilityCollapsedConverter}}"
278280
BorderThickness="0"
279281
Cursor="Hand"
280-
Click="DropDownInstallButton_OnClick"
281282
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
282283
<Image Source=" /DynamoCoreWpf;component/UI/Images/caret_drop_down.png"
283284
Width="7"

src/DynamoCoreWpf/Views/PackageManager/Controls/PackageManagerPackagesControl.xaml.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,12 @@ private void CloseToastButton_OnClick(object sender, RoutedEventArgs e)
149149
return;
150150
}
151151

152-
153152

154153
private void DropDownInstallButton_OnClick(object sender, RoutedEventArgs e)
155154
{
156155
var button = sender as Button;
157-
if (button == null) { return; }
158-
156+
if (button == null || button.DataContext == null) { return; }
157+
159158
var contextMenu = new ContextMenu();
160159
var commandBinding = new Binding("DownloadLatestToCustomPathCommand");
161160
commandBinding.Source = button.DataContext;
@@ -187,6 +186,37 @@ private void DropDownInstallButton_OnClick(object sender, RoutedEventArgs e)
187186

188187
// Open the context menu when the left mouse button is pressed
189188
contextMenu.IsOpen = true;
190-
}
189+
}
190+
191+
// Attach the 'context menu' button to the parent button
192+
private void DropDownInstallButton_Loaded(object sender, RoutedEventArgs e)
193+
{
194+
var installButton = sender as Button;
195+
if (installButton != null)
196+
{
197+
var dropDownInstallButton = installButton.Template.FindName("dropDownInstallButton", installButton) as Button;
198+
if (dropDownInstallButton != null)
199+
{
200+
dropDownInstallButton.Click -= DropDownInstallButton_OnClick;
201+
202+
// Now that the parent button is loaded, we can assign the Click event to the context menu button
203+
dropDownInstallButton.Click += DropDownInstallButton_OnClick;
204+
}
205+
}
206+
}
207+
208+
// Dispose of DropDownInstallButton_OnClick when the parent button is unloaded
209+
private void DropDownInstallButton_Unloaded(object sender, RoutedEventArgs e)
210+
{
211+
var installButton = sender as Button;
212+
if (installButton != null)
213+
{
214+
var dropDownInstallButton = installButton.Template.FindName("dropDownInstallButton", installButton) as Button;
215+
if (dropDownInstallButton != null)
216+
{
217+
dropDownInstallButton.Click -= DropDownInstallButton_OnClick;
218+
}
219+
}
220+
}
191221
}
192222
}

src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,14 @@
293293
DataContext="{Binding PackageManagerViewModel}"
294294
VerticalAlignment="Stretch"
295295
Height="650"
296-
Visibility="{Binding PackageManagerViewModel.LocalPackages, Converter={StaticResource ListHasMoreThanNItemsToVisibilityConverter}}" />
296+
Visibility="{Binding LocalPackages, Converter={StaticResource ListHasMoreThanNItemsToVisibilityConverter}}" />
297297

298298

299-
<!--Empty list screen-->
299+
<!--Empty list screen-->
300300
<StackPanel Orientation="Vertical"
301301
VerticalAlignment="Center"
302302
HorizontalAlignment="Center"
303-
Margin="0 0 0 73"
303+
Margin="0 127 0 0"
304304
Visibility="{Binding PackageManagerViewModel.LocalPackages, Converter={StaticResource EmptyListToVisibilityConverter }}">
305305
<Image HorizontalAlignment="Center"
306306
VerticalAlignment="Center"

0 commit comments

Comments
 (0)