Skip to content

Commit 7add3e7

Browse files
committed
Merge remote-tracking branch 'refs/remotes/ButchersBoy/master' into FixVirtualizingComboBox
2 parents c1544ac + ae4502b commit 7add3e7

File tree

13 files changed

+561
-202
lines changed

13 files changed

+561
-202
lines changed

MainDemo.Wpf/MainDemo.Wpf.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
<Compile Include="Shadows.xaml.cs">
123123
<DependentUpon>Shadows.xaml</DependentUpon>
124124
</Compile>
125+
<Compile Include="Sliders.xaml.cs">
126+
<DependentUpon>Sliders.xaml</DependentUpon>
127+
</Compile>
125128
<Compile Include="TextFields.xaml.cs">
126129
<DependentUpon>TextFields.xaml</DependentUpon>
127130
</Compile>
@@ -204,6 +207,10 @@
204207
<SubType>Designer</SubType>
205208
<Generator>MSBuild:Compile</Generator>
206209
</Page>
210+
<Page Include="Sliders.xaml">
211+
<SubType>Designer</SubType>
212+
<Generator>MSBuild:Compile</Generator>
213+
</Page>
207214
<Page Include="TextFields.xaml">
208215
<SubType>Designer</SubType>
209216
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
<wpfExample:TextFields />
7171
</domain:DemoItem.Content>
7272
</domain:DemoItem>
73+
<domain:DemoItem Name="Sliders">
74+
<domain:DemoItem.Content>
75+
<wpfExample:Sliders />
76+
</domain:DemoItem.Content>
77+
</domain:DemoItem>
7378
<domain:DemoItem Name="Cards">
7479
<domain:DemoItem.Content>
7580
<wpfExample:Cards />

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,29 @@
99
Background="{DynamicResource MaterialDesignPaper}"
1010
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
1111
mc:Ignorable="d"
12-
d:DesignWidth="200" d:DesignHeight="120">
12+
d:DesignWidth="477" d:DesignHeight="272">
1313
<UserControl.Resources>
1414
<ResourceDictionary>
1515
<ResourceDictionary.MergedDictionaries>
16-
17-
<!-- light or dark theme -->
1816
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
19-
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
20-
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
21-
22-
<!-- primary color -->
23-
<ResourceDictionary>
24-
<!-- include your primary palette -->
25-
<ResourceDictionary.MergedDictionaries>
26-
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Indigo.xaml" />
27-
</ResourceDictionary.MergedDictionaries>
28-
<!--
29-
include three hues from the primary palette (and the associated forecolours).
30-
Do not rename, keep in sequence; light to dark.
31-
-->
32-
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
33-
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
34-
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource Primary500}"/>
35-
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
36-
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary700}"/>
37-
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary700Foreground}"/>
38-
</ResourceDictionary>
39-
40-
<!-- secondary colour -->
41-
<ResourceDictionary>
42-
<!-- include your secondary pallette -->
43-
<ResourceDictionary.MergedDictionaries>
44-
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Yellow.xaml" />
45-
</ResourceDictionary.MergedDictionaries>
46-
47-
<!-- include a single secondary accent color (and the associated forecolour) -->
48-
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent700}"/>
49-
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent700Foreground}"/>
50-
</ResourceDictionary>
17+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Slider.xaml" />
18+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
19+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
5120
</ResourceDictionary.MergedDictionaries>
52-
53-
54-
5521
</ResourceDictionary>
56-
57-
58-
5922
</UserControl.Resources>
6023

61-
62-
<Grid>
63-
<wpf:Clock DisplayAutomation="None" Is24Hours="False" VerticalAlignment="Center" HorizontalAlignment="Center">
64-
</wpf:Clock>
65-
66-
</Grid>
67-
6824

25+
<StackPanel Margin="24 0 0 0" HorizontalAlignment="Stretch">
26+
<StackPanel Orientation="Horizontal">
27+
<TextBlock VerticalAlignment="Bottom">Try me</TextBlock>
28+
<Slider Minimum="0" Maximum="100" Style="{StaticResource MaterialDesignDiscreteSlider}"
29+
Value="50"
30+
Width="280"
31+
Margin="8 0 0 0"/>
32+
</StackPanel>
33+
<Slider Minimum="0" Maximum="10" Margin="0 24 0 0" Style="{StaticResource MaterialDesignDiscreteSlider}" />
34+
<Slider Minimum="0" Maximum="10" Margin="0 24 0 0" Style="{StaticResource MaterialDesignDiscreteSlider}" />
35+
</StackPanel>
6936

7037
</UserControl>

MainDemo.Wpf/Sliders.xaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Sliders"
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="300" d:DesignWidth="300">
9+
10+
<UserControl.Resources>
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<!-- note you only need bring in these extra resource dictionaries when using non-default styles, so only bring them into your controls where the default style is not what you want -->
14+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Slider.xaml" />
15+
</ResourceDictionary.MergedDictionaries>
16+
</ResourceDictionary>
17+
</UserControl.Resources>
18+
19+
<Grid VerticalAlignment="Top">
20+
<Grid.ColumnDefinitions>
21+
<ColumnDefinition />
22+
<ColumnDefinition />
23+
</Grid.ColumnDefinitions>
24+
<Grid.RowDefinitions>
25+
<RowDefinition Height="Auto" />
26+
<RowDefinition Height="Auto" />
27+
<RowDefinition Height="Auto" />
28+
<RowDefinition Height="Auto" />
29+
<RowDefinition Height="Auto" />
30+
<RowDefinition Height="Auto" />
31+
</Grid.RowDefinitions>
32+
<Slider Grid.Row="0" TickFrequency="5" Orientation="Horizontal" Minimum="1" Maximum="50" Value="25" />
33+
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1" Grid.RowSpan="3"
34+
Margin="0 36 0 0">
35+
<Slider TickFrequency="5" TickPlacement="BottomRight" Orientation="Vertical" Minimum="1" Maximum="50" />
36+
<Slider TickFrequency="25" TickPlacement="TopLeft" Orientation="Vertical" Minimum="1" Maximum="50" IsEnabled="False" Margin="24 8 0 8" />
37+
</StackPanel>
38+
<Slider Grid.Row="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsSelectionRangeEnabled="True"
39+
Margin="0 36 0 0" />
40+
<Slider Grid.Row="2" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False"
41+
Margin="0 36 0 0" />
42+
43+
<StackPanel Orientation="Horizontal" Grid.Row="3" Margin="0 16 0 0">
44+
<TextBlock VerticalAlignment="Bottom">Try me</TextBlock>
45+
<Slider Minimum="0" Maximum="100" Style="{StaticResource MaterialDesignDiscreteSlider}"
46+
Value="50"
47+
Width="280"
48+
Margin="8 0 0 0"/>
49+
</StackPanel>
50+
<Slider Minimum="0" Maximum="10" Margin="0 24 0 0" Style="{StaticResource MaterialDesignDiscreteSlider}" Grid.Row="4" Width="260" HorizontalAlignment="Left" />
51+
<Slider Minimum="0" Maximum="10" Margin="0 24 0 0" Style="{StaticResource MaterialDesignDiscreteSlider}" Grid.Row="5" Width="260" HorizontalAlignment="Left" />
52+
53+
</Grid>
54+
</UserControl>

MainDemo.Wpf/Sliders.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+
/// Interaction logic for Sliders.xaml
20+
/// </summary>
21+
public partial class Sliders : UserControl
22+
{
23+
public Sliders()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

MainDemo.Wpf/TextFields.xaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
<RowDefinition Height="Auto" />
5252
<RowDefinition Height="Auto" />
5353
<RowDefinition Height="Auto" />
54-
<RowDefinition Height="Auto" />
55-
<RowDefinition Height="Auto" />
56-
<RowDefinition Height="Auto" />
5754
</Grid.RowDefinitions>
5855
<Viewbox Grid.Row="0" Grid.Column="0">
5956
<Canvas Width="24" Height="24">
@@ -179,14 +176,6 @@
179176
wpf:TextFieldAssist.Hint="Pick Date"/>
180177
<wpf:TimePicker Grid.Row="5" Grid.Column="3" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 8 0 8"
181178
wpf:TextFieldAssist.Hint="Custom hint" />
182-
<wpf:TimePicker Grid.Row="5" Grid.Column="4" Is24Hours="True" x:Name="PresetTimePicker" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 8 0 8" />
183-
<Slider Grid.Row="6" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" Minimum="1" Maximum="50" Value="25" />
184-
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="3" Grid.RowSpan="3" >
185-
<Slider TickFrequency="5" TickPlacement="BottomRight" Orientation="Vertical" Minimum="1" Maximum="50" />
186-
<Slider TickFrequency="25" TickPlacement="TopLeft" Orientation="Vertical" Minimum="1" Maximum="50" IsEnabled="False" Margin="24 8 0 8" />
187-
</StackPanel>
188-
<Slider Grid.Row="7" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsSelectionRangeEnabled="True" />
189-
<Slider Grid.Row="8" Grid.Column="1" TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False" />
190-
179+
<wpf:TimePicker Grid.Row="5" Grid.Column="4" Is24Hours="True" x:Name="PresetTimePicker" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 8 0 8" />
191180
</Grid>
192181
</UserControl>

MaterialDesignColors.Wpf/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.CompilerServices;
44
using System.Runtime.InteropServices;
55
using System.Windows;
6+
using System.Windows.Markup;
67

78
// General Information about an assembly is controlled through the following
89
// set of attributes. Change these attribute values to modify the information
@@ -15,6 +16,8 @@
1516
[assembly: AssemblyCopyright("Copyright © 2015")]
1617
[assembly: AssemblyTrademark("")]
1718
[assembly: AssemblyCulture("")]
19+
[assembly: XmlnsPrefix("http://materialdesigninxaml.net/winfx/xaml/colors", "materialDesignColor")]
20+
[assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/colors", "MaterialDesignColors.Wpf")]
1821

1922
// Setting ComVisible to false makes the types in this assembly not visible
2023
// to COM components. If you need to access a type in this assembly from

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,35 @@
1212

1313
namespace MaterialDesignThemes.Wpf
1414
{
15+
/// <summary>
16+
/// Defines how a data context is sourced for a dialog if a <see cref="FrameworkElement"/>
17+
/// is passed as the command parameter when using <see cref="DialogHost.OpenDialogCommand"/>.
18+
/// </summary>
19+
public enum DialogHostOpenDialogCommandDataContextSource
20+
{
21+
/// <summary>
22+
/// The data context from the sender element (typically a <see cref="Button"/>)
23+
/// is applied to the content.
24+
/// </summary>
25+
SenderElement,
26+
/// <summary>
27+
/// The data context from the <see cref="DialogHost"/> is applied to the content.
28+
/// </summary>
29+
DialogHostInstance,
30+
/// <summary>
31+
/// The data context is explicitly set to <c>null</c>.
32+
/// </summary>
33+
None
34+
}
35+
1536
[TemplatePart(Name = PopupPartName, Type = typeof(Popup))]
37+
[TemplatePart(Name = PopupPartName, Type = typeof(ContentControl))]
1638
[TemplateVisualState(GroupName = "PopupStates", Name = OpenStateName)]
1739
[TemplateVisualState(GroupName = "PopupStates", Name = ClosedStateName)]
1840
public class DialogHost : ContentControl
1941
{
2042
public const string PopupPartName = "PART_Popup";
43+
public const string PopupContentPartName = "PART_PopupContentElement";
2144
public const string OpenStateName = "Open";
2245
public const string ClosedStateName = "Closed";
2346

@@ -37,10 +60,11 @@ public class DialogHost : ContentControl
3760
private DialogClosingEventHandler _asyncShowClosingEventHandler;
3861

3962
private Popup _popup;
63+
private ContentControl _popupContentControl;
64+
private DialogSession _session;
4065
private DialogOpenedEventHandler _attachedDialogOpenedEventHandler;
4166
private DialogClosingEventHandler _attachedDialogClosingEventHandler;
4267
private object _closeDialogExecutionParameter;
43-
private DialogSession _session;
4468

4569
static DialogHost()
4670
{
@@ -276,9 +300,23 @@ public string DialogContentStringFormat
276300
set { SetValue(DialogContentStringFormatProperty, value); }
277301
}
278302

303+
public static readonly DependencyProperty OpenDialogCommandDataContextSourceProperty = DependencyProperty.Register(
304+
"OpenDialogCommandDataContextSource", typeof (DialogHostOpenDialogCommandDataContextSource), typeof (DialogHost), new PropertyMetadata(default(DialogHostOpenDialogCommandDataContextSource)));
305+
306+
/// <summary>
307+
/// Defines how a data context is sourced for a dialog if a <see cref="FrameworkElement"/>
308+
/// is passed as the command parameter when using <see cref="DialogHost.OpenDialogCommand"/>.
309+
/// </summary>
310+
public DialogHostOpenDialogCommandDataContextSource OpenDialogCommandDataContextSource
311+
{
312+
get { return (DialogHostOpenDialogCommandDataContextSource) GetValue(OpenDialogCommandDataContextSourceProperty); }
313+
set { SetValue(OpenDialogCommandDataContextSourceProperty, value); }
314+
}
315+
279316
public override void OnApplyTemplate()
280317
{
281-
_popup = GetTemplateChild(PopupPartName) as Popup;
318+
_popup = GetTemplateChild(PopupPartName) as Popup;
319+
_popupContentControl = GetTemplateChild(PopupContentPartName) as ContentControl;
282320

283321
VisualStateManager.GoToState(this, SelectState(), false);
284322

@@ -373,7 +411,7 @@ public static DialogClosingEventHandler GetDialogClosingAttached(DependencyObjec
373411
}
374412

375413
public static readonly DependencyProperty DialogClosingCallbackProperty = DependencyProperty.Register(
376-
"DialogClosingCallback", typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
414+
"DialogClosingCallback", typeof (DialogClosingEventHandler), typeof (DialogHost), new PropertyMetadata(default(DialogClosingEventHandler)));
377415

378416
/// <summary>
379417
/// Callback fired when the <see cref="DialogClosing"/> event is fired, allowing the event to be processed from a binding/view model.
@@ -438,19 +476,26 @@ private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRo
438476
{
439477
AssertTargetableContent();
440478

441-
//TODO enhancement: make the following configurable, so that the data context can be pulled from the dialog host if desired.
442-
// (leave the current behaviour as the default; most developers will find this logical, as the data context will "inherit" from button containing the content)
443-
444-
var contentElement = executedRoutedEventArgs.Parameter as FrameworkElement;
445-
var senderElement = executedRoutedEventArgs.OriginalSource as FrameworkElement;
446-
if (contentElement != null && senderElement != null && contentElement.DataContext == null && BindingOperations.GetBindingExpression(contentElement, DataContextProperty) == null)
479+
if (_popupContentControl != null)
447480
{
448-
DialogContent = executedRoutedEventArgs.Parameter;
449-
contentElement.SetCurrentValue(DataContextProperty, senderElement.DataContext);
481+
switch (OpenDialogCommandDataContextSource)
482+
{
483+
case DialogHostOpenDialogCommandDataContextSource.SenderElement:
484+
_popupContentControl.DataContext =
485+
(executedRoutedEventArgs.Parameter as FrameworkElement)?.DataContext;
486+
break;
487+
case DialogHostOpenDialogCommandDataContextSource.DialogHostInstance:
488+
_popupContentControl.DataContext = DataContext;
489+
break;
490+
case DialogHostOpenDialogCommandDataContextSource.None:
491+
_popupContentControl.DataContext = null;
492+
break;
493+
default:
494+
throw new ArgumentOutOfRangeException();
495+
}
450496
}
451-
else
452-
DialogContent = executedRoutedEventArgs.Parameter;
453497

498+
DialogContent = executedRoutedEventArgs.Parameter;
454499
}
455500

456501
SetCurrentValue(IsOpenProperty, true);
@@ -467,7 +512,7 @@ private void CloseDialogHandler(object sender, ExecutedRoutedEventArgs executedR
467512
{
468513
if (executedRoutedEventArgs.Handled) return;
469514

470-
Close(executedRoutedEventArgs.Parameter);
515+
Close(executedRoutedEventArgs.Parameter);
471516

472517
executedRoutedEventArgs.Handled = true;
473518
}

MaterialDesignThemes.Wpf/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.CompilerServices;
44
using System.Runtime.InteropServices;
55
using System.Windows;
6+
using System.Windows.Markup;
67

78
// General Information about an assembly is controlled through the following
89
// set of attributes. Change these attribute values to modify the information
@@ -15,7 +16,8 @@
1516
[assembly: AssemblyCopyright("Copyright © 2015")]
1617
[assembly: AssemblyTrademark("")]
1718
[assembly: AssemblyCulture("")]
18-
19+
[assembly: XmlnsPrefix("http://materialdesigninxaml.net/winfx/xaml/themes", "materialDesign")]
20+
[assembly: XmlnsDefinition("http://materialdesigninxaml.net/winfx/xaml/themes", "MaterialDesignThemes.Wpf")]
1921

2022
// Setting ComVisible to false makes the types in this assembly not visible
2123
// to COM components. If you need to access a type in this assembly from

0 commit comments

Comments
 (0)