Skip to content

Commit bc96e46

Browse files
committed
template for Expander and experimental multiple selection drop down
1 parent 22fedd2 commit bc96e46

12 files changed

+464
-7
lines changed

MainDemo.Wpf/Expander.xaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Expander"
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:MaterialDesignColors.WpfExample"
7+
mc:Ignorable="d"
8+
d:DesignHeight="400" d:DesignWidth="600">
9+
<Grid>
10+
<Grid.ColumnDefinitions>
11+
<ColumnDefinition Width="50*" />
12+
<ColumnDefinition Width="50*" />
13+
</Grid.ColumnDefinitions>
14+
<StackPanel HorizontalAlignment="Stretch" Margin="8" Orientation="Vertical" VerticalAlignment="Stretch">
15+
<Expander IsExpanded="True" HorizontalAlignment="Stretch">
16+
<Expander.Header>
17+
<TextBlock Text="Expander Example 1" />
18+
</Expander.Header>
19+
<TextBlock Text="A short text to proof functionality." />
20+
</Expander>
21+
<TextBlock Text="Text after the expander." Margin="0,8,0,0" />
22+
</StackPanel>
23+
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch" Margin="8" Orientation="Vertical" VerticalAlignment="Stretch">
24+
<Expander IsExpanded="False" HorizontalAlignment="Stretch">
25+
<Expander.Header>
26+
<TextBlock Text="Expander Example 1" />
27+
</Expander.Header>
28+
<TextBlock Text="A short text to proof functionality." />
29+
</Expander>
30+
<TextBlock Text="Text after the expander." Margin="0,8,0,0" />
31+
</StackPanel>
32+
</Grid>
33+
</UserControl>

MainDemo.Wpf/Expander.xaml.cs

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
17+
{
18+
/// <summary>
19+
/// Interaktionslogik für Expander.xaml
20+
/// </summary>
21+
public partial class Expander : UserControl
22+
{
23+
public Expander()
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
@@ -85,6 +85,9 @@
8585
<Compile Include="Domain\ListFieldsViewModel.cs" />
8686
<Compile Include="Domain\SelectableViewModel.cs" />
8787
<Compile Include="Domain\TextFieldsViewModel.cs" />
88+
<Compile Include="Expander.xaml.cs">
89+
<DependentUpon>Expander.xaml</DependentUpon>
90+
</Compile>
8891
<Compile Include="Grids.xaml.cs">
8992
<DependentUpon>Grids.xaml</DependentUpon>
9093
</Compile>
@@ -129,6 +132,10 @@
129132
<SubType>Designer</SubType>
130133
<Generator>MSBuild:Compile</Generator>
131134
</Page>
135+
<Page Include="Expander.xaml">
136+
<SubType>Designer</SubType>
137+
<Generator>MSBuild:Compile</Generator>
138+
</Page>
132139
<Page Include="Grids.xaml">
133140
<SubType>Designer</SubType>
134141
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
</wpfExample:Grids>
105105
</domain:DemoItem.Content>
106106
</domain:DemoItem>
107+
<domain:DemoItem Name="Expander">
108+
<domain:DemoItem.Content>
109+
<wpfExample:Expander />
110+
</domain:DemoItem.Content>
111+
</domain:DemoItem>
107112
<domain:DemoItem Name="Menus &amp; Tool Bars">
108113
<domain:DemoItem.Content>
109114
<wpfExample:MenusAndToolBars />

MainDemo.Wpf/TextFields.xaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@
151151
<Slider TickFrequency="25" TickPlacement="TopLeft" Orientation="Vertical" Minimum="1" Maximum="50" IsEnabled="False" Margin="24 8 0 8" />
152152
</StackPanel>
153153
<Slider Grid.Row="7" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsSelectionRangeEnabled="True" />
154-
<Slider Grid.Row="8" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False" />
155-
156-
</Grid>
154+
<Slider Grid.Row="8" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False" />
155+
156+
<wpf:MultipleSelectionDropDown x:Name="multipleSelectionDropDown" Grid.Column="4" Grid.Row="3" Height="30" Width="100">
157+
</wpf:MultipleSelectionDropDown>
158+
159+
</Grid>
157160
</UserControl>

MainDemo.Wpf/TextFields.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ public partial class TextFields : UserControl
2727
public TextFields()
2828
{
2929
InitializeComponent();
30-
DataContext = new TextFieldsViewModel();
31-
}
30+
DataContext = new TextFieldsViewModel();
31+
32+
List<string> items = new List<string>();
33+
items.Add("item A");
34+
items.Add("item B");
35+
items.Add("item C");
36+
items.Add("item D");
37+
items.Add("item E");
38+
items.Add("item F");
39+
items.Add("item G");
40+
multipleSelectionDropDown.ItemsSource = items;
41+
}
3242

3343
private void UserControl_Loaded(object sender, RoutedEventArgs e)
3444
{

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
<SubType>Designer</SubType>
9393
<Generator>MSBuild:Compile</Generator>
9494
</Page>
95+
<Page Include="Themes\MaterialDesignTheme.Expander.xaml">
96+
<SubType>Designer</SubType>
97+
<Generator>MSBuild:Compile</Generator>
98+
</Page>
9599
<Page Include="Themes\MaterialDesignTheme.GridSplitter.xaml">
96100
<SubType>Designer</SubType>
97101
<Generator>MSBuild:Compile</Generator>
@@ -112,6 +116,10 @@
112116
<SubType>Designer</SubType>
113117
<Generator>MSBuild:Compile</Generator>
114118
</Page>
119+
<Page Include="Themes\MaterialDesignTheme.MultipleSelectionDropDown.xaml">
120+
<SubType>Designer</SubType>
121+
<Generator>MSBuild:Compile</Generator>
122+
</Page>
115123
<Page Include="Themes\MaterialDesignTheme.PasswordBox.xaml">
116124
<SubType>Designer</SubType>
117125
<Generator>MSBuild:Compile</Generator>
@@ -225,6 +233,7 @@
225233
<Compile Include="MaterialDataGridComboBoxColumn.cs" />
226234
<Compile Include="MaterialDataGridTextColumn.cs" />
227235
<Compile Include="MaterialDateDisplay.cs" />
236+
<Compile Include="MultipleSelectionDropDown.cs" />
228237
<Compile Include="PaletteHelper.cs" />
229238
<Compile Include="PasswordFieldAssist.cs" />
230239
<Compile Include="ProgressLoop.cs" />
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Controls.Primitives;
10+
using System.Windows.Input;
11+
using System.Windows.Markup;
12+
13+
namespace MaterialDesignThemes.Wpf
14+
{
15+
[ContentProperty("ItemsSource")]
16+
public class MultipleSelectionDropDown : ItemsControl
17+
{
18+
/*public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(MultipleSelectionDropDown));
19+
20+
public IEnumerable ItemsSource
21+
{
22+
get
23+
{
24+
return (IEnumerable)GetValue(ItemsSourceProperty);
25+
}
26+
27+
set
28+
{
29+
SetValue(ItemsSourceProperty, value);
30+
}
31+
}*/
32+
33+
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register("IsOpen", typeof(bool), typeof(MultipleSelectionDropDown));
34+
35+
public bool IsOpen
36+
{
37+
get
38+
{
39+
return (bool)GetValue(IsOpenProperty);
40+
}
41+
42+
set
43+
{
44+
SetValue(IsOpenProperty, value);
45+
}
46+
}
47+
48+
public static DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(IEnumerable), typeof(MultipleSelectionDropDown));
49+
50+
public IEnumerable SelectedItems
51+
{
52+
get
53+
{
54+
return (IEnumerable)GetValue(SelectedItemsProperty);
55+
}
56+
57+
set
58+
{
59+
SetValue(SelectedItemsProperty, value);
60+
61+
if (value != null && _popupList != null)
62+
{
63+
_popupList.SelectedItems.Clear();
64+
}
65+
}
66+
}
67+
68+
private Button _dropDownButton;
69+
private Popup _popup;
70+
private ListBox _popupList;
71+
72+
static MultipleSelectionDropDown()
73+
{
74+
DefaultStyleKeyProperty.OverrideMetadata(typeof(MultipleSelectionDropDown), new FrameworkPropertyMetadata(typeof(MultipleSelectionDropDown)));
75+
}
76+
77+
public MultipleSelectionDropDown()
78+
{
79+
_dropDownButton = null;
80+
_popup = null;
81+
_popupList = null;
82+
}
83+
84+
public override void OnApplyTemplate()
85+
{
86+
base.OnApplyTemplate();
87+
88+
InitControls();
89+
}
90+
91+
private void InitControls()
92+
{
93+
_dropDownButton = GetTemplateChild("PART_DropDownButton") as Button;
94+
_popup = GetTemplateChild("PART_Popup") as Popup;
95+
_popupList = GetTemplateChild("PART_PopupList") as ListBox;
96+
97+
_dropDownButton.Click -= DropDownButtonClickHandler;
98+
_dropDownButton.Click += DropDownButtonClickHandler;
99+
100+
_popupList.SelectionChanged -= PopupListSelectionChangedHandler;
101+
_popupList.SelectionChanged += PopupListSelectionChangedHandler;
102+
103+
_popup.Opened -= PopupOpenedHandler;
104+
_popup.Opened += PopupOpenedHandler;
105+
106+
_popup.Closed -= PopupClosedHandler;
107+
_popup.Closed += PopupClosedHandler;
108+
}
109+
110+
private void DropDownButtonClickHandler(object sender, RoutedEventArgs args)
111+
{
112+
IsOpen = !IsOpen;
113+
}
114+
115+
private void PopupOpenedHandler(object sender, EventArgs args)
116+
{
117+
Mouse.Capture(this, CaptureMode.SubTree);
118+
Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OutsideCapturedElementHandler);
119+
}
120+
121+
private void PopupClosedHandler(object sender, EventArgs args)
122+
{
123+
ReleaseMouseCapture();
124+
}
125+
126+
private void OutsideCapturedElementHandler(object sender, MouseButtonEventArgs mouseButtonEventArgs)
127+
{
128+
IsOpen = false;
129+
Mouse.RemovePreviewMouseDownOutsideCapturedElementHandler(this, OutsideCapturedElementHandler);
130+
}
131+
132+
private void PopupListSelectionChangedHandler(object sender, SelectionChangedEventArgs args)
133+
{
134+
ReleaseMouseCapture();
135+
Mouse.Capture(this, CaptureMode.SubTree);
136+
}
137+
}
138+
}

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
in you App.xaml
1515
-->
1616
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Card.xaml" />
17-
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Clock.xaml" />
17+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Clock.xaml" />
18+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.MultipleSelectionDropDown.xaml" />
1819
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.RatingBar.xaml" />
1920
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TimePicker.xaml" />
2021
</ResourceDictionary.MergedDictionaries>
2122

2223
<!-- set up default styles for our custom Material Design in XAML Toolkit controls -->
2324
<Style TargetType="{x:Type local:Clock}" BasedOn="{StaticResource MaterialDesignClock}" />
24-
<Style TargetType="{x:Type local:TimePicker}" BasedOn="{StaticResource MaterialDesignTimePicker}" />
25+
<Style TargetType="{x:Type local:TimePicker}" BasedOn="{StaticResource MaterialDesignTimePicker}" />
26+
<Style TargetType="{x:Type local:MultipleSelectionDropDown}" BasedOn="{StaticResource MaterialDesignMultipleSelectionDropDown}" />
2527

2628
<converters:BrushToRadialGradientBrushConverter x:Key="BrushToRadialGradientBrushConverter" />
2729

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.combobox.xaml" />
1313
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DataGrid.xaml" />
1414
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DatePicker.xaml" />
15+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Expander.xaml" />
1516
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.GridView.xaml" />
1617
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.GridSplitter.xaml" />
1718
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.Label.xaml" />
@@ -40,6 +41,7 @@
4041
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource MaterialDesignDataGridRow}" />
4142
<Style TargetType="{x:Type DataGridRowHeader}" BasedOn="{StaticResource MaterialDesignDataGridRowHeader}" />
4243
<Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource MaterialDesignDatePicker}" />
44+
<Style TargetType="{x:Type Expander}" BasedOn="{StaticResource MaterialDesignExpander}" />
4345
<Style TargetType="{x:Type GridSplitter}" BasedOn="{StaticResource MaterialDesignGridSplitter}" />
4446
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource MaterialDesignLabel}" />
4547
<Style TargetType="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignListBox}" />

0 commit comments

Comments
 (0)