Skip to content

Commit 92a21ca

Browse files
authored
Fixes #945 (#1141)
The issue is the PopupOnLoaded method that was setting the IsOpen property directly on the Popup. This would lock the popup in an opened state when it was hidden by the tab control. When coming back to the popup box the popup would not properly trigger the IpOpen change from the trigger preventing it from showing up again, effectively killing all of the contents in the popup
1 parent 44f4874 commit 92a21ca

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ protected virtual void OnClosed()
386386

387387
public override void OnApplyTemplate()
388388
{
389-
if (_popup != null)
390-
_popup.Loaded -= PopupOnLoaded;
391389
if (_toggleButton != null)
392390
_toggleButton.PreviewMouseLeftButtonUp -= ToggleButtonOnPreviewMouseLeftButtonUp;
393391

@@ -396,9 +394,7 @@ public override void OnApplyTemplate()
396394
_popup = GetTemplateChild(PopupPartName) as PopupEx;
397395
_popupContentControl = GetTemplateChild(PopupContentControlPartName) as ContentControl;
398396
_toggleButton = GetTemplateChild(TogglePartName) as ToggleButton;
399-
400-
if (_popup != null)
401-
_popup.Loaded += PopupOnLoaded;
397+
402398
if (_toggleButton != null)
403399
_toggleButton.PreviewMouseLeftButtonUp += ToggleButtonOnPreviewMouseLeftButtonUp;
404400

@@ -726,12 +722,6 @@ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
726722

727723
#endregion
728724

729-
private void PopupOnLoaded(object sender, RoutedEventArgs routedEventArgs)
730-
{
731-
if (PopupMode == PopupBoxPopupMode.MouseOverEager)
732-
_popup.IsOpen = true;
733-
}
734-
735725
private void ToggleButtonOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
736726
{
737727
if (PopupMode == PopupBoxPopupMode.Click || !IsPopupOpen) return;

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PopupBox.xaml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@
101101
Cursor="Hand"
102102
VerticalAlignment="Center"
103103
/>
104-
<controlzEx:PopupEx x:Name="PART_Popup" IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=TwoWay}"
105-
CustomPopupPlacementCallback="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PopupPlacementMethod}"
104+
<controlzEx:PopupEx x:Name="PART_Popup"
105+
IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=TwoWay}"
106+
CustomPopupPlacementCallback="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PopupPlacementMethod}"
106107
HorizontalOffset="5"
107108
VerticalOffset="5"
108109
PlacementTarget="{Binding ElementName=PART_Toggle}"
@@ -114,7 +115,7 @@
114115
FontSize="15"
115116
FontWeight="Regular"
116117
Padding="{TemplateBinding Padding}"
117-
RenderOptions.ClearTypeHint="Enabled"
118+
RenderOptions.ClearTypeHint="Enabled"
118119
Margin="5">
119120
<wpf:Card.Resources>
120121
<Style TargetType="Button" BasedOn="{StaticResource MaterialDesignPopupBoxButton}" />
@@ -305,13 +306,14 @@
305306
</Storyboard>
306307
</ControlTemplate.Resources>
307308
<Grid>
308-
<ToggleButton x:Name="PART_Toggle" Style="{StaticResource ToggleButtonStyle}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=TwoWay}"
309+
<ToggleButton x:Name="PART_Toggle" Style="{StaticResource ToggleButtonStyle}"
310+
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=TwoWay}"
309311
Cursor="Hand"
310312
Background="{TemplateBinding Background}"
311313
BorderBrush="{TemplateBinding BorderBrush}"
312314
Foreground="{TemplateBinding Foreground}"
313315
VerticalAlignment="Stretch"
314-
HorizontalAlignment="Stretch"
316+
HorizontalAlignment="Stretch"
315317
ToolTip="{TemplateBinding ToolTip}"
316318
ToolTipService.Placement="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=(ToolTipService.Placement)}">
317319
<Grid>
@@ -332,14 +334,14 @@
332334
</ToggleButton>
333335
<controlzEx:PopupEx x:Name="PART_Popup"
334336
IsOpen="False"
335-
CustomPopupPlacementCallback="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PopupPlacementMethod}"
337+
CustomPopupPlacementCallback="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PopupPlacementMethod}"
336338
PlacementTarget="{Binding ElementName=PART_Toggle}"
337339
Placement="Custom"
338-
PopupAnimation="None"
340+
PopupAnimation="None"
339341
AllowsTransparency="True">
340342
<Grid>
341343
<!-- with PopupBox.PopupMode == MouseOverEager the popup is always open, with
342-
content hidden. but Transparent doesnt seem to register hit test in the popup.
344+
content hidden. but Transparent doesn't seem to register hit test in the popup.
343345
this opacity is the lowest I could get to register hit test. might try and speak
344346
to MS about this one, I *think* it is a bug -->
345347
<Border Background="White" Opacity="0.002" />
@@ -377,9 +379,13 @@
377379
<BeginStoryboard Storyboard="{StaticResource Close}" />
378380
</Trigger.ExitActions>
379381
</Trigger>
380-
<Trigger Property="PopupMode" Value="MouseOverEager">
382+
<MultiTrigger>
383+
<MultiTrigger.Conditions>
384+
<Condition Property="PopupMode" Value="MouseOverEager" />
385+
<Condition Property="IsVisible" Value="True" />
386+
</MultiTrigger.Conditions>
381387
<Setter TargetName="PART_Popup" Property="IsOpen" Value="True" />
382-
</Trigger>
388+
</MultiTrigger>
383389
</ControlTemplate.Triggers>
384390
</ControlTemplate>
385391
</Setter.Value>

0 commit comments

Comments
 (0)