Skip to content

Commit 749c898

Browse files
committed
add default button style for default popupbox style
1 parent 75d9819 commit 749c898

File tree

6 files changed

+135
-12
lines changed

6 files changed

+135
-12
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Domain.SampleMessageDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
7+
mc:Ignorable="d"
8+
d:DesignHeight="300" d:DesignWidth="300"
9+
MaxWidth="400">
10+
<Grid Margin="16">
11+
<Grid.RowDefinitions>
12+
<RowDefinition />
13+
<RowDefinition />
14+
</Grid.RowDefinitions>
15+
<TextBlock x:Name="Message"
16+
Margin="0 6 0 0"
17+
FontSize="18" Grid.Row="0"/>
18+
<Button Grid.Row="1"
19+
IsDefault="True" Style="{DynamicResource MaterialDesignFlatButton}"
20+
HorizontalAlignment="Right"
21+
Margin="16 16 16 0"
22+
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}">
23+
ACCEPT
24+
</Button>
25+
</Grid>
26+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MaterialDesignColors.WpfExample.Domain
17+
{
18+
/// <summary>
19+
/// Interaction logic for SampleMessageDialog.xaml
20+
/// </summary>
21+
public partial class SampleMessageDialog : UserControl
22+
{
23+
public SampleMessageDialog()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

MainDemo.Wpf/MainDemo.Wpf.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
<Compile Include="Domain\SampleDialog.xaml.cs">
9393
<DependentUpon>SampleDialog.xaml</DependentUpon>
9494
</Compile>
95+
<Compile Include="Domain\SampleMessageDialog.xaml.cs">
96+
<DependentUpon>SampleMessageDialog.xaml</DependentUpon>
97+
</Compile>
9598
<Compile Include="Domain\SampleProgressDialog.xaml.cs">
9699
<DependentUpon>SampleProgressDialog.xaml</DependentUpon>
97100
</Compile>
@@ -155,6 +158,10 @@
155158
<SubType>Designer</SubType>
156159
<Generator>MSBuild:Compile</Generator>
157160
</Page>
161+
<Page Include="Domain\SampleMessageDialog.xaml">
162+
<SubType>Designer</SubType>
163+
<Generator>MSBuild:Compile</Generator>
164+
</Page>
158165
<Page Include="Expander.xaml">
159166
<SubType>Designer</SubType>
160167
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/MainWindow.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Window.Resources>
1717
<ResourceDictionary>
1818
<ResourceDictionary.MergedDictionaries>
19+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
1920
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
2021
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
2122
</ResourceDictionary.MergedDictionaries>
@@ -165,12 +166,11 @@
165166
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="False"
166167
x:Name="MenuToggleButton"/>
167168
<materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges">
168-
<ListBox Margin="0 6 0 6">
169-
<ListBoxItem>Hello World</ListBoxItem>
170-
<ListBoxItem>Nice Popup</ListBoxItem>
171-
<ListBoxItem>Goodbye.</ListBoxItem>
172-
<ListBoxItem><Button x:Name="PopupButton" Content="Button" Click="PopupButton_OnClick"/></ListBoxItem>
173-
</ListBox>
169+
<StackPanel>
170+
<Button Content="Hello World" Click="MenuPopupButton_OnClick"/>
171+
<Button Content="Nice Popup" Click="MenuPopupButton_OnClick"/>
172+
<Button Content="Goodbye" Click="MenuPopupButton_OnClick"/>
173+
</StackPanel>
174174
</materialDesign:PopupBox>
175175
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>
176176
</DockPanel>

MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using System.Windows;
2+
using System.Windows.Controls;
3+
using System.Windows.Controls.Primitives;
24
using System.Windows.Input;
5+
using MaterialDesignColors.WpfExample.Domain;
6+
using MaterialDesignThemes.Wpf;
37

48
namespace MaterialDesignColors.WpfExample
59
{
@@ -18,9 +22,14 @@ private void UIElement_OnPreviewMouseLeftButtonUp(object sender, MouseButtonEven
1822
MenuToggleButton.IsChecked = false;
1923
}
2024

21-
private void PopupButton_OnClick(object sender, RoutedEventArgs e)
25+
private async void MenuPopupButton_OnClick(object sender, RoutedEventArgs e)
2226
{
23-
MessageBox.Show("PopupButton Clicked");
27+
var sampleMessageDialog = new SampleMessageDialog
28+
{
29+
Message = {Text = ((ButtonBase) sender).Content.ToString()}
30+
};
31+
32+
await DialogHost.Show(sampleMessageDialog, "RootDialog");
2433
}
2534
}
2635
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PopupBox.xaml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
1313
<converters:NullableToVisibilityConverter x:Key="NullVisibilityConverter" />
14-
<converters:NullableToVisibilityConverter x:Key="InvertedNullVisibilityConverter" NullValue="Visible" NotNullValue="Collapsed" />
15-
14+
<converters:NullableToVisibilityConverter x:Key="InvertedNullVisibilityConverter" NullValue="Visible" NotNullValue="Collapsed" />
15+
<converters:BrushRoundConverter x:Key="BrushRoundConverter"/>
16+
1617
<Style TargetType="{x:Type wpf:PopupBox}" x:Key="MaterialDesignPopupBox">
1718
<Setter Property="ToggleContent">
1819
<Setter.Value>
@@ -59,8 +60,60 @@
5960
Placement="Custom"
6061
PopupAnimation="Fade"
6162
AllowsTransparency="True">
62-
<wpf:Card Content="{TemplateBinding PopupContent}" ContentTemplate="{TemplateBinding PopupContentTemplate}"
63-
Margin="5" />
63+
<wpf:Card Content="{TemplateBinding PopupContent}" ContentTemplate="{TemplateBinding PopupContentTemplate}"
64+
FontSize="15"
65+
FontWeight="Regular"
66+
Padding="0 8 0 8"
67+
RenderOptions.ClearTypeHint="Enabled"
68+
Margin="5">
69+
<wpf:Card.Resources>
70+
<Style TargetType="{x:Type Button}">
71+
<Setter Property="VerticalContentAlignment" Value="Bottom" />
72+
<Setter Property="HorizontalContentAlignment" Value="Left" />
73+
<Setter Property="Padding" Value="16 0 16 16" />
74+
<Setter Property="Template">
75+
<Setter.Value>
76+
<ControlTemplate TargetType="{x:Type Button}">
77+
<Grid>
78+
<VisualStateManager.VisualStateGroups>
79+
<VisualStateGroup Name="CommonStates">
80+
<VisualStateGroup.Transitions>
81+
<VisualTransition GeneratedDuration="0:0:0.3" To="Normal">
82+
<VisualTransition.GeneratedEasingFunction>
83+
<CircleEase EasingMode="EaseOut"/>
84+
</VisualTransition.GeneratedEasingFunction>
85+
</VisualTransition>
86+
</VisualStateGroup.Transitions>
87+
<VisualState Name="Normal"/>
88+
<VisualState Name="MouseOver">
89+
<Storyboard>
90+
<DoubleAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="Opacity"
91+
To="0.1" Duration="0"/>
92+
</Storyboard>
93+
</VisualState>
94+
<VisualState Name="Disabled"/>
95+
</VisualStateGroup>
96+
</VisualStateManager.VisualStateGroups>
97+
<Border x:Name="MouseOverBorder"
98+
Opacity="0"
99+
Background="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"/>
100+
<wpf:Ripple Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
101+
Focusable="False"
102+
MinHeight="48"
103+
Content="{TemplateBinding Content}"
104+
ContentTemplate="{TemplateBinding ContentTemplate}"
105+
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
106+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
107+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
108+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
109+
Padding="{TemplateBinding Padding}"/>
110+
</Grid>
111+
</ControlTemplate>
112+
</Setter.Value>
113+
</Setter>
114+
</Style>
115+
</wpf:Card.Resources>
116+
</wpf:Card>
64117
</controlzEx:PopupEx>
65118
</Grid>
66119
</ControlTemplate>

0 commit comments

Comments
 (0)