|
| 1 | +<UserControl x:Class="MaterialDesignDemo.PopupBox" |
| 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:local="clr-namespace:MaterialDesignDemo" |
| 7 | + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" |
| 8 | + xmlns:system="clr-namespace:System;assembly=System.Runtime" |
| 9 | + mc:Ignorable="d" |
| 10 | + d:DesignHeight="450" d:DesignWidth="800"> |
| 11 | + <UserControl.Resources> |
| 12 | + <ResourceDictionary> |
| 13 | + <!-- This is needed to avoid runtime exceptions?! Seems like this might be a bug? --> |
| 14 | + <ResourceDictionary.MergedDictionaries> |
| 15 | + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" /> |
| 16 | + </ResourceDictionary.MergedDictionaries> |
| 17 | + |
| 18 | + <DataTemplate x:Key="ContentTemplateGrid"> |
| 19 | + <Grid Width="200" Height="100" TextElement.Foreground="{DynamicResource MaterialDesignLightForeground}"> |
| 20 | + <TextBlock Text="Popup content in grid" HorizontalAlignment="Center" VerticalAlignment="Center" /> |
| 21 | + </Grid> |
| 22 | + </DataTemplate> |
| 23 | + |
| 24 | + <DataTemplate x:Key="ContentTemplateGridWithBackground"> |
| 25 | + <Grid Width="200" Height="100" Background="Fuchsia"> |
| 26 | + <TextBlock Text="Popup content in colored grid" HorizontalAlignment="Center" VerticalAlignment="Center" /> |
| 27 | + </Grid> |
| 28 | + </DataTemplate> |
| 29 | + |
| 30 | + <DataTemplate x:Key="ContentTemplateButtonStack"> |
| 31 | + <!-- Margin of 10 here is to "make room" for the elevation drop shadows of the buttons. Must be compensated for in some (left/right) alignment scenarios using PopupBox.PopupHorizontalOffset --> |
| 32 | + <StackPanel Margin="10"> |
| 33 | + <Button Content="1" |
| 34 | + Opacity="0.5" |
| 35 | + ToolTip="One with custom opacity" /> |
| 36 | + <Button Content="2" ToolTip="Two" /> |
| 37 | + <Button Content="3" ToolTip="Three" /> |
| 38 | + </StackPanel> |
| 39 | + </DataTemplate> |
| 40 | + |
| 41 | + <DataTemplate x:Key="ContentTemplateButtonStackWithBackground"> |
| 42 | + <Grid Background="Fuchsia"> |
| 43 | + <StackPanel Margin="10"> |
| 44 | + <Button Content="1" |
| 45 | + Opacity="0.5" |
| 46 | + ToolTip="One with custom opacity" /> |
| 47 | + <Button Content="2" ToolTip="Two" /> |
| 48 | + <Button Content="3" ToolTip="Three" /> |
| 49 | + </StackPanel> |
| 50 | + </Grid> |
| 51 | + </DataTemplate> |
| 52 | + |
| 53 | + <x:Array x:Key="{x:Static local:PopupBox.DefaultStyleContentKey}" Type="ComboBoxItem"> |
| 54 | + <ComboBoxItem Tag="{StaticResource ContentTemplateGrid}" materialDesign:HintAssist.HelperText="Selected content works best when used with the MaterialDesignPopupBox style">Grid</ComboBoxItem> |
| 55 | + <ComboBoxItem Tag="{StaticResource ContentTemplateGridWithBackground}">Colored grid</ComboBoxItem> |
| 56 | + </x:Array> |
| 57 | + |
| 58 | + <x:Array x:Key="{x:Static local:PopupBox.MultiFloatingActionStyleContentKey}" Type="ComboBoxItem"> |
| 59 | + <ComboBoxItem Tag="{StaticResource ContentTemplateButtonStack}" materialDesign:HintAssist.HelperText="Margin in the selected content (stack of buttons) needs to be compensated for in certain alignments (left/right)">Stack of buttons</ComboBoxItem> |
| 60 | + <ComboBoxItem Tag="{StaticResource ContentTemplateButtonStackWithBackground}">Stack of buttons in colored grid</ComboBoxItem> |
| 61 | + </x:Array> |
| 62 | + |
| 63 | + <local:ComboBoxItemToDataTemplateConverter x:Key="ComboBoxItemToDataTemplateConverter" /> |
| 64 | + <local:ComboBoxItemToStyleConverter x:Key="ComboBoxItemToStyleConverter" /> |
| 65 | + <local:ComboBoxItemToHelperTextConverter x:Key="ComboBoxItemToHelperTextConverter" /> |
| 66 | + |
| 67 | + <Thickness x:Key="Spacer">0,30,0,0</Thickness> |
| 68 | + </ResourceDictionary> |
| 69 | + </UserControl.Resources> |
| 70 | + <Grid> |
| 71 | + <Grid.ColumnDefinitions> |
| 72 | + <ColumnDefinition Width="*" /> |
| 73 | + <ColumnDefinition Width="250" /> |
| 74 | + </Grid.ColumnDefinitions> |
| 75 | + |
| 76 | + <Grid Grid.Column="0"> |
| 77 | + <Grid.RowDefinitions> |
| 78 | + <RowDefinition Height="Auto" /> |
| 79 | + <RowDefinition Height="*" /> |
| 80 | + </Grid.RowDefinitions> |
| 81 | + |
| 82 | + <TextBlock Grid.Row="0" HorizontalAlignment="Center" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" |
| 83 | + Text="{Binding ElementName=ContentComboBox, Path=SelectedItem, Converter={StaticResource ComboBoxItemToHelperTextConverter}}" /> |
| 84 | + |
| 85 | + <materialDesign:PopupBox Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True" Padding="0" |
| 86 | + Style="{Binding ElementName=StyleComboBox, Path=SelectedItem, Converter={StaticResource ComboBoxItemToStyleConverter}}" |
| 87 | + PopupElevation="{Binding ElementName=ElevationComboBox, Path=SelectedItem}" |
| 88 | + PopupUniformCornerRadius="{Binding ElementName=UniformCornerRadiusComboBox, Path=SelectedItem}" |
| 89 | + PopupHorizontalOffset="{Binding ElementName=HorizontalOffsetComboBox, Path=SelectedItem}" |
| 90 | + PopupVerticalOffset="{Binding ElementName=VerticalOffsetComboBox, Path=SelectedItem}" |
| 91 | + PlacementMode="{Binding ElementName=PopupBoxPlacementModeComboBox, Path=SelectedItem}"> |
| 92 | + <ContentControl ContentTemplate="{Binding ElementName=ContentComboBox, Path=SelectedItem, Converter={StaticResource ComboBoxItemToDataTemplateConverter}}" /> |
| 93 | + </materialDesign:PopupBox> |
| 94 | + </Grid> |
| 95 | + |
| 96 | + <StackPanel Grid.Column="1" Orientation="Vertical"> |
| 97 | + <GroupBox Header="Properties" Padding="10"> |
| 98 | + <StackPanel Orientation="Vertical"> |
| 99 | + <TextBlock Text="Style:" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 100 | + <ComboBox x:Name="StyleComboBox" SelectionChanged="StyleComboBox_OnSelectionChanged"> |
| 101 | + <ComboBoxItem Tag="{StaticResource MaterialDesignPopupBox}">MaterialDesignPopupBox</ComboBoxItem> |
| 102 | + <ComboBoxItem Tag="{StaticResource MaterialDesignMultiFloatingActionPopupBox}">MaterialDesignMultiFloatingActionPopupBox</ComboBoxItem> |
| 103 | + </ComboBox> |
| 104 | + |
| 105 | + <TextBlock Text="Elevation:" Margin="{StaticResource Spacer}" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 106 | + <ComboBox x:Name="ElevationComboBox" SelectedIndex="6"> |
| 107 | + <materialDesign:Elevation>Dp0</materialDesign:Elevation> |
| 108 | + <materialDesign:Elevation>Dp1</materialDesign:Elevation> |
| 109 | + <materialDesign:Elevation>Dp2</materialDesign:Elevation> |
| 110 | + <materialDesign:Elevation>Dp3</materialDesign:Elevation> |
| 111 | + <materialDesign:Elevation>Dp4</materialDesign:Elevation> |
| 112 | + <materialDesign:Elevation>Dp5</materialDesign:Elevation> |
| 113 | + <materialDesign:Elevation>Dp6</materialDesign:Elevation> |
| 114 | + <materialDesign:Elevation>Dp7</materialDesign:Elevation> |
| 115 | + <materialDesign:Elevation>Dp8</materialDesign:Elevation> |
| 116 | + <materialDesign:Elevation>Dp12</materialDesign:Elevation> |
| 117 | + <materialDesign:Elevation>Dp16</materialDesign:Elevation> |
| 118 | + <materialDesign:Elevation>Dp24</materialDesign:Elevation> |
| 119 | + </ComboBox> |
| 120 | + |
| 121 | + <TextBlock Text="PopupUniformCornerRadius:" Margin="{StaticResource Spacer}" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 122 | + <ComboBox x:Name="UniformCornerRadiusComboBox" SelectedIndex="2"> |
| 123 | + <system:Double>0</system:Double> |
| 124 | + <system:Double>2</system:Double> |
| 125 | + <system:Double>4</system:Double> |
| 126 | + <system:Double>6</system:Double> |
| 127 | + <system:Double>8</system:Double> |
| 128 | + <system:Double>10</system:Double> |
| 129 | + <system:Double>20</system:Double> |
| 130 | + </ComboBox> |
| 131 | + |
| 132 | + <TextBlock Text="PopupHorizontalOffset:" Margin="{StaticResource Spacer}" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 133 | + <ComboBox x:Name="HorizontalOffsetComboBox" SelectedIndex="10"> |
| 134 | + <system:Double>-100</system:Double> |
| 135 | + <system:Double>-50</system:Double> |
| 136 | + <system:Double>-20</system:Double> |
| 137 | + <system:Double>-15</system:Double> |
| 138 | + <system:Double>-10</system:Double> |
| 139 | + <system:Double>-5</system:Double> |
| 140 | + <system:Double>-4</system:Double> |
| 141 | + <system:Double>-3</system:Double> |
| 142 | + <system:Double>-2</system:Double> |
| 143 | + <system:Double>-1</system:Double> |
| 144 | + <system:Double>0</system:Double> |
| 145 | + <system:Double>1</system:Double> |
| 146 | + <system:Double>2</system:Double> |
| 147 | + <system:Double>3</system:Double> |
| 148 | + <system:Double>4</system:Double> |
| 149 | + <system:Double>5</system:Double> |
| 150 | + <system:Double>10</system:Double> |
| 151 | + <system:Double>15</system:Double> |
| 152 | + <system:Double>20</system:Double> |
| 153 | + <system:Double>50</system:Double> |
| 154 | + <system:Double>100</system:Double> |
| 155 | + </ComboBox> |
| 156 | + |
| 157 | + <TextBlock Text="PopupVerticalOffset:" Margin="{StaticResource Spacer}" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 158 | + <ComboBox x:Name="VerticalOffsetComboBox" SelectedIndex="10"> |
| 159 | + <system:Double>-100</system:Double> |
| 160 | + <system:Double>-50</system:Double> |
| 161 | + <system:Double>-20</system:Double> |
| 162 | + <system:Double>-15</system:Double> |
| 163 | + <system:Double>-10</system:Double> |
| 164 | + <system:Double>-5</system:Double> |
| 165 | + <system:Double>-4</system:Double> |
| 166 | + <system:Double>-3</system:Double> |
| 167 | + <system:Double>-2</system:Double> |
| 168 | + <system:Double>-1</system:Double> |
| 169 | + <system:Double>0</system:Double> |
| 170 | + <system:Double>1</system:Double> |
| 171 | + <system:Double>2</system:Double> |
| 172 | + <system:Double>3</system:Double> |
| 173 | + <system:Double>4</system:Double> |
| 174 | + <system:Double>5</system:Double> |
| 175 | + <system:Double>10</system:Double> |
| 176 | + <system:Double>15</system:Double> |
| 177 | + <system:Double>20</system:Double> |
| 178 | + <system:Double>50</system:Double> |
| 179 | + <system:Double>100</system:Double> |
| 180 | + </ComboBox> |
| 181 | + |
| 182 | + <TextBlock Text="PopupBoxPlacementMode:" Margin="{StaticResource Spacer}" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 183 | + <ComboBox x:Name="PopupBoxPlacementModeComboBox" SelectedIndex="1"> |
| 184 | + <materialDesign:PopupBoxPlacementMode>BottomAndAlignCentres</materialDesign:PopupBoxPlacementMode> |
| 185 | + <materialDesign:PopupBoxPlacementMode>BottomAndAlignLeftEdges</materialDesign:PopupBoxPlacementMode> |
| 186 | + <materialDesign:PopupBoxPlacementMode>BottomAndAlignRightEdges</materialDesign:PopupBoxPlacementMode> |
| 187 | + <materialDesign:PopupBoxPlacementMode>LeftAndAlignBottomEdges</materialDesign:PopupBoxPlacementMode> |
| 188 | + <materialDesign:PopupBoxPlacementMode>LeftAndAlignMiddles</materialDesign:PopupBoxPlacementMode> |
| 189 | + <materialDesign:PopupBoxPlacementMode>LeftAndAlignTopEdges</materialDesign:PopupBoxPlacementMode> |
| 190 | + <materialDesign:PopupBoxPlacementMode>RightAndAlignBottomEdges</materialDesign:PopupBoxPlacementMode> |
| 191 | + <materialDesign:PopupBoxPlacementMode>RightAndAlignMiddles</materialDesign:PopupBoxPlacementMode> |
| 192 | + <materialDesign:PopupBoxPlacementMode>RightAndAlignTopEdges</materialDesign:PopupBoxPlacementMode> |
| 193 | + <materialDesign:PopupBoxPlacementMode>TopAndAlignCentres</materialDesign:PopupBoxPlacementMode> |
| 194 | + <materialDesign:PopupBoxPlacementMode>TopAndAlignLeftEdges</materialDesign:PopupBoxPlacementMode> |
| 195 | + <materialDesign:PopupBoxPlacementMode>TopAndAlignRightEdges</materialDesign:PopupBoxPlacementMode> |
| 196 | + </ComboBox> |
| 197 | + </StackPanel> |
| 198 | + </GroupBox> |
| 199 | + |
| 200 | + <GroupBox Header="Popup" Margin="{StaticResource Spacer}" Padding="10"> |
| 201 | + <StackPanel Orientation="Vertical"> |
| 202 | + <TextBlock Text="Popup Content:" Style="{StaticResource MaterialDesignSubtitle2TextBlock}" /> |
| 203 | + <ComboBox x:Name="ContentComboBox" /> |
| 204 | + </StackPanel> |
| 205 | + </GroupBox> |
| 206 | + </StackPanel> |
| 207 | + </Grid> |
| 208 | +</UserControl> |
0 commit comments