Skip to content

Commit ca046a5

Browse files
committed
floating action buttons and tooltips ligning up nicely
1 parent 77f5923 commit ca046a5

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private CustomPopupPlacement[] GetPopupPlacement(Size popupSize, Size targetSize
220220
y = targetSize.Height - Math.Abs(offset.Y);
221221
break;
222222
case PopupBoxPlacementMode.BottomAndAlignCentres:
223-
x = targetSize.Width/2 - popupSize.Width/2;
223+
x = targetSize.Width/2 - popupSize.Width/2 - Math.Abs(offset.X*2);
224224
y = targetSize.Height - Math.Abs(offset.Y);
225225
break;
226226
case PopupBoxPlacementMode.TopAndAlignLeftEdges:
@@ -232,7 +232,7 @@ private CustomPopupPlacement[] GetPopupPlacement(Size popupSize, Size targetSize
232232
y = 0 - popupSize.Height - Math.Abs(offset.Y * 2);
233233
break;
234234
case PopupBoxPlacementMode.TopAndAlignCentres:
235-
x = targetSize.Width / 2 - popupSize.Width / 2;
235+
x = targetSize.Width/2 - popupSize.Width/2 - Math.Abs(offset.X*2);
236236
y = 0 - popupSize.Height - Math.Abs(offset.Y * 2);
237237
break;
238238
default:

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PopupBox.xaml

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
55
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters">
66

7+
<ResourceDictionary.MergedDictionaries>
8+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
9+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToolTip.xaml" />
10+
</ResourceDictionary.MergedDictionaries>
11+
712
<Style TargetType="{x:Type wpf:PopupBox}" x:Key="MaterialDesignPopupBox">
813
<Setter Property="ToggleContent">
914
<Setter.Value>
@@ -64,6 +69,7 @@
6469
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
6570
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidForegroundBrush}"/>
6671
<Setter Property="PlacementMode" Value="TopAndAlignCentres" />
72+
<Setter Property="ToolTipService.Placement" Value="Left" />
6773
<Setter Property="HorizontalAlignment" Value="Left" />
6874
<Setter Property="BorderThickness" Value="1"/>
6975
<Setter Property="Cursor" Value="Hand"/>
@@ -167,46 +173,31 @@
167173
HorizontalAlignment="Stretch"
168174
/>
169175
<controlz:PopupEx x:Name="PART_Popup" IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsPopupOpen, Mode=TwoWay}"
170-
CustomPopupPlacementCallback="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PopupPlacementMethod}"
171-
HorizontalOffset="5"
172-
VerticalOffset="5"
176+
CustomPopupPlacementCallback="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PopupPlacementMethod}"
173177
PlacementTarget="{Binding ElementName=PART_Toggle}"
174178
Placement="Custom"
175179
PopupAnimation="Fade"
176180
AllowsTransparency="True">
177-
<wpf:Card Content="{TemplateBinding PopupContent}" ContentTemplate="{TemplateBinding PopupContentTemplate}"
181+
<Border Background="Transparent">
182+
<ContentControl Content="{TemplateBinding PopupContent}" ContentTemplate="{TemplateBinding PopupContentTemplate}"
178183
Margin="5" Padding="8">
179-
<wpf:Card.Resources>
180-
<ResourceDictionary>
181-
<Style TargetType="{x:Type Button}">
182-
<Style.Setters>
183-
<Setter Property="Background" Value="{DynamicResource MaterialDesignPrimaryLightBrush}" />
184-
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignPrimaryLightForegroundBrush}" />
185-
<Setter Property="ToolTipService.IsEnabled" Value="False" />
186-
<Setter Property="Template">
187-
<Setter.Value>
188-
<ControlTemplate TargetType="{x:Type Button}">
189-
<StackPanel Orientation="Horizontal" Margin="8">
190-
<Grid Clip="{Binding ElementName=UncheckedEllipse, Path=RenderedGeometry}" ClipToBounds="True" Background="{TemplateBinding Background}"
191-
Width="30" Height="30">
192-
<Ellipse Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" x:Name="UncheckedEllipse" />
193-
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
194-
</Grid>
195-
<Border Background="{DynamicResource MaterialDesignToolTipBackground}" Margin="8 0 0 0" Padding="8">
196-
<ContentControl Foreground="{DynamicResource MaterialDesignPaper}" Content="{TemplateBinding ToolTip}" VerticalAlignment="Center" />
197-
</Border>
198-
</StackPanel>
199-
</ControlTemplate>
200-
</Setter.Value>
201-
</Setter>
202-
</Style.Setters>
203-
</Style>
204-
</ResourceDictionary>
205-
</wpf:Card.Resources>
206-
<wpf:Card.Background>
207-
<SolidColorBrush Color="White" Opacity=".6" />
208-
</wpf:Card.Background>
209-
</wpf:Card>
184+
<ContentControl.Resources>
185+
<ResourceDictionary>
186+
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource MaterialDesignToolTip}">
187+
<Style.Setters>
188+
<Setter Property="Margin" Value="16 4 16 4" />
189+
</Style.Setters>
190+
</Style>
191+
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
192+
<Style.Setters>
193+
<Setter Property="ToolTipService.Placement" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=(ToolTipService.Placement)}"/>
194+
<Setter Property="Margin" Value="4" />
195+
</Style.Setters>
196+
</Style>
197+
</ResourceDictionary>
198+
</ContentControl.Resources>
199+
</ContentControl>
200+
</Border>
210201
</controlz:PopupEx>
211202
</Grid>
212203
</ControlTemplate>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ToolTip.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<Setter Property="Template">
1111
<Setter.Value>
1212
<ControlTemplate TargetType="{x:Type ToolTip}">
13-
<Border Background="{TemplateBinding Background}" CornerRadius="2">
13+
<Border Background="{TemplateBinding Background}" CornerRadius="2" Margin="{TemplateBinding Margin}">
1414
<ContentPresenter x:Name="ContentPresenter"
15-
Margin="{TemplateBinding Padding}"
16-
Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}">
15+
Margin="{TemplateBinding Padding}"
16+
Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}">
1717
</ContentPresenter>
1818
</Border>
1919
</ControlTemplate>

0 commit comments

Comments
 (0)