Skip to content

Commit 6afcd3c

Browse files
committed
use PopupEx for DialogHost
1 parent e02bc66 commit 6afcd3c

File tree

3 files changed

+19
-44
lines changed

3 files changed

+19
-44
lines changed

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
54
using System.Threading;
65
using System.Threading.Tasks;
76
using System.Windows;
@@ -93,7 +92,6 @@ public DialogHost()
9392
{
9493
Loaded += OnLoaded;
9594
Unloaded += OnUnloaded;
96-
SizeChanged += (sender, args) => TriggerPopupReposition();
9795

9896
CommandBindings.Add(new CommandBinding(CloseDialogCommand, CloseDialogHandler));
9997
CommandBindings.Add(new CommandBinding(OpenDialogCommand, OpenDialogHandler));
@@ -294,45 +292,15 @@ private string SelectState()
294292
return IsOpen ? OpenStateName : ClosedStateName;
295293
}
296294

297-
private void TriggerPopupReposition()
298-
{
299-
if (_popup == null) return;
300-
301-
_popup.HorizontalOffset++;
302-
_popup.HorizontalOffset--;
303-
}
304-
305295
private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)
306296
{
307297
LoadedInstances.Remove(this);
308-
309-
if (_window != null)
310-
{
311-
_window.LocationChanged -= WindowOnLocationChanged;
312-
_window.SizeChanged -= WindowOnSizeChanged;
313-
}
314298
SetCurrentValue(IsOpenProperty, false);
315299
}
316300

317301
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
318302
{
319303
LoadedInstances.Add(this);
320-
321-
_window = Window.GetWindow(this);
322-
if (_window == null) return;
323-
324-
_window.LocationChanged += WindowOnLocationChanged;
325-
_window.SizeChanged += WindowOnSizeChanged;
326-
}
327-
328-
private void WindowOnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
329-
{
330-
TriggerPopupReposition();
331-
}
332-
333-
private void WindowOnLocationChanged(object sender, EventArgs eventArgs)
334-
{
335-
TriggerPopupReposition();
336304
}
337305
}
338306
}

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:MaterialDesignThemes.Wpf"
5-
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters">
5+
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
6+
xmlns:controlz="clr-namespace:Controlz">
67

78
<ResourceDictionary.MergedDictionaries>
89
<!-- we only bring in the dictionaries for controls which were "invented"
@@ -416,7 +417,7 @@
416417
<Setter Property="Template">
417418
<Setter.Value>
418419
<ControlTemplate TargetType="local:DialogHost">
419-
<Grid Focusable="False">
420+
<Grid x:Name="DialogHostRoot" Focusable="False">
420421
<VisualStateManager.VisualStateGroups>
421422
<VisualStateGroup x:Name="PopupStates">
422423
<VisualStateGroup.Transitions>
@@ -528,24 +529,28 @@
528529
</VisualState>
529530
</VisualStateGroup>
530531
</VisualStateManager.VisualStateGroups>
531-
<Popup IsOpen="False" StaysOpen="True" AllowsTransparency="True" PopupAnimation="None"
532-
x:Name="PART_Popup"
533-
Placement="Center">
532+
<controlz:PopupEx IsOpen="False"
533+
PlacementTarget="{Binding ElementName=DialogHostRoot, Mode=OneWay}"
534+
StaysOpen="True"
535+
AllowsTransparency="True"
536+
PopupAnimation="None"
537+
x:Name="PART_Popup"
538+
Placement="Center">
534539
<Popup.Resources>
535540
<ResourceDictionary>
536541
<ResourceDictionary.MergedDictionaries>
537542
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
538543
</ResourceDictionary.MergedDictionaries>
539544
</ResourceDictionary>
540545
</Popup.Resources>
541-
<local:Card Margin="22"
546+
<local:Card Margin="22"
542547
local:ShadowAssist.ShadowDepth="Depth5"
543548
UniformCornerRadius="4"
544549
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
545550
TextElement.FontWeight="Medium"
546551
TextElement.FontSize="14"
547-
TextOptions.TextFormattingMode="Ideal"
548-
TextOptions.TextRenderingMode="Auto"
552+
TextOptions.TextFormattingMode="Ideal"
553+
TextOptions.TextRenderingMode="Auto"
549554
Foreground="{DynamicResource MaterialDesignBody}"
550555
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
551556
IsTabStop="False"
@@ -555,14 +560,16 @@
555560
Content="{TemplateBinding DialogContent}"
556561
ContentTemplate="{TemplateBinding DialogContentTemplate}"
557562
ContentTemplateSelector="{TemplateBinding DialogContentTemplateSelector}"
558-
ContentStringFormat="{TemplateBinding DialogContentStringFormat}">
563+
ContentStringFormat="{TemplateBinding ContentStringFormat}">
559564
<local:Card.RenderTransform>
560565
<TransformGroup>
561-
<ScaleTransform x:Name="CardScaleTransform" ScaleX="0" ScaleY="0" />
566+
<ScaleTransform x:Name="CardScaleTransform"
567+
ScaleX="0"
568+
ScaleY="0" />
562569
</TransformGroup>
563570
</local:Card.RenderTransform>
564571
</local:Card>
565-
</Popup>
572+
</controlz:PopupEx>
566573
<ContentPresenter
567574
x:Name="ContentPresenter" Opacity="1"
568575
Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />

paket.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
GITHUB
33
remote: punker76/Controlz
44
specs:
5-
src/Controlz/Controlz/PopupEx.cs (60eb353aa53f85bc57f4ff3a46dddcb45838a382)
5+
src/Controlz/Controlz/PopupEx.cs (60eb353aa53f85bc57f4ff3a46dddcb45838a382)

0 commit comments

Comments
 (0)