Skip to content

Commit 175faaf

Browse files
timuniepunker76
authored andcommitted
Added a way to access the different Styles
1 parent f248e19 commit 175faaf

File tree

7 files changed

+111
-7
lines changed

7 files changed

+111
-7
lines changed

src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MahApps.Metro.Demo_v2;
22
using System;
3+
using System.Collections;
34
using System.Collections.Generic;
45
using System.ComponentModel;
56
using System.Linq;
@@ -69,7 +70,7 @@ public DemoViewProperty(DependencyProperty dependencyProperty, DependencyObject
6970
public static readonly DependencyProperty DataTemplateProperty = DependencyProperty.Register(nameof(DataTemplate), typeof(DataTemplate), typeof(DemoViewProperty), new PropertyMetadata(null));
7071

7172
/// <summary>Identifies the <see cref="ItemSource"/> dependency property.</summary>
72-
public static readonly DependencyProperty ItemSourceProperty = DependencyProperty.Register(nameof(ItemSource), typeof(IEnumerable<object>), typeof(DemoViewProperty), new PropertyMetadata(null));
73+
public static readonly DependencyProperty ItemSourceProperty = DependencyProperty.Register(nameof(ItemSource), typeof(IEnumerable), typeof(DemoViewProperty), new PropertyMetadata(null));
7374

7475
/// <summary>Identifies the <see cref="GroupName"/> dependency property.</summary>
7576
public static readonly DependencyProperty GroupNameProperty = DependencyProperty.Register(nameof(GroupName), typeof(string), typeof(DemoViewProperty), new PropertyMetadata(null));
@@ -145,6 +146,9 @@ public DataTemplate DataTemplate
145146

146147
private DataTemplate GetDefaultDataTemplate(DependencyProperty dependencyProperty)
147148
{
149+
// Any Object
150+
if (dependencyProperty.PropertyType == typeof(object)) return null;
151+
148152
// Numeric
149153
if (dependencyProperty.PropertyType.IsAssignableFrom(typeof(sbyte)) ||
150154
dependencyProperty.PropertyType.IsAssignableFrom(typeof(byte)) ||
@@ -156,7 +160,7 @@ private DataTemplate GetDefaultDataTemplate(DependencyProperty dependencyPropert
156160
dependencyProperty.PropertyType.IsAssignableFrom(typeof(ulong)) ||
157161
dependencyProperty.PropertyType.IsAssignableFrom(typeof(float)) ||
158162
dependencyProperty.PropertyType.IsAssignableFrom(typeof(double)) ||
159-
dependencyProperty.PropertyType. IsAssignableFrom(typeof(decimal)))
163+
dependencyProperty.PropertyType.IsAssignableFrom(typeof(decimal)))
160164
{
161165
return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Numeric"] as DataTemplate;
162166
}
@@ -176,15 +180,20 @@ dependencyProperty.PropertyType. IsAssignableFrom(typeof(decimal)))
176180
return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Enum"] as DataTemplate;
177181
}
178182

183+
if (dependencyProperty.PropertyType.IsAssignableFrom(typeof(Style)))
184+
{
185+
return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Styles"] as DataTemplate;
186+
}
187+
179188
return null;
180189
}
181190

182191
/// <summary>
183192
/// Gets or Sets the ItemSource used for selectable <see cref="Value"/>
184193
/// </summary>
185-
public IEnumerable<object> ItemSource
194+
public IEnumerable ItemSource
186195
{
187-
get { return (IEnumerable<object>)GetValue(ItemSourceProperty); }
196+
get { return (IEnumerable)GetValue(ItemSourceProperty); }
188197
set { SetValue(ItemSourceProperty, value); }
189198
}
190199

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<UserControl x:Class="MahApps.Demo.ExampleViews.ButtonExample"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:ctrls="clr-namespace:MahApps.Demo.Controls"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MahApps.Demo.ExampleViews"
7+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
d:DesignHeight="450"
10+
d:DesignWidth="800"
11+
mc:Ignorable="d">
12+
<ctrls:DemoView x:Name="demoView"
13+
xml:space="preserve"
14+
HyperlinkOnlineDocs="https://mahapps.com/docs/styles/buttons">
15+
<ctrls:DemoView.ExampleXaml> <![CDATA[<Button
16+
Content="Click Me"
17+
Margin="5"
18+
HorizontalAlignment="Stretch"
19+
VerticalAlignment="Center"
20+
IsEnabled="True" /> ]]>
21+
</ctrls:DemoView.ExampleXaml>
22+
<Button x:Name="button"
23+
Content="Click Me"
24+
Margin="5"
25+
HorizontalAlignment="Stretch"
26+
VerticalAlignment="Center"
27+
IsEnabled="True" />
28+
</ctrls:DemoView>
29+
</UserControl>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using MahApps.Demo.Controls;
2+
using MahApps.Metro.Demo_v2;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace MahApps.Demo.ExampleViews
19+
{
20+
/// <summary>
21+
/// Interaction logic for UserControl1.xaml
22+
/// </summary>
23+
public partial class ButtonExample : UserControl
24+
{
25+
public ButtonExample()
26+
{
27+
InitializeComponent();
28+
29+
demoView.DemoProperties.Add(new DemoViewProperty(Button.ContentProperty, button));
30+
demoView.DemoProperties.Add(new DemoViewProperty(Button.HorizontalAlignmentProperty, button));
31+
demoView.DemoProperties.Add(new DemoViewProperty(Button.VerticalAlignmentProperty, button));
32+
demoView.DemoProperties.Add(new DemoViewProperty(Button.WidthProperty, button));
33+
demoView.DemoProperties.Add(new DemoViewProperty(Button.HeightProperty, button));
34+
35+
var styleProperty = new DemoViewProperty(Button.StyleProperty, button);
36+
styleProperty.ItemSource = new Dictionary<string, Style>()
37+
{
38+
{"MahApps.Styles.Button", App.Current.Resources["MahApps.Styles.Button"] as Style},
39+
{"MahApps.Styles.Button.Circle", App.Current.Resources["MahApps.Styles.Button.Circle"] as Style}
40+
};
41+
demoView.DemoProperties.Add(styleProperty);
42+
}
43+
}
44+
}

src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public NumericUpDownExample()
3939
demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.InterceptMouseWheelProperty, numericUpDown, "NumericUpDown"));
4040

4141
demoView.DemoProperties.Add(new DemoViewProperty(TextBoxHelper.ClearTextButtonProperty, numericUpDown, "Attached"));
42+
4243
}
4344
}
4445
}

src/MahApps.Metro.Demo_v2/MainWindow.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
<views:NumericUpDownExample />
5050
</mah:HamburgerMenuIconItem.Tag>
5151
</mah:HamburgerMenuIconItem>
52+
53+
<mah:HamburgerMenuSeparatorItem />
54+
<mah:HamburgerMenuHeaderItem Label="Styles" />
55+
56+
<mah:HamburgerMenuIconItem Icon="{iconPacks:Modern Kind=InterfaceButton, Width=20, Height=20}" Label="Button">
57+
<mah:HamburgerMenuIconItem.Tag>
58+
<views:ButtonExample />
59+
</mah:HamburgerMenuIconItem.Tag>
60+
</mah:HamburgerMenuIconItem>
61+
5262
</mah:HamburgerMenuItemCollection>
5363
</mah:HamburgerMenu.ItemsSource>
5464
</mah:HamburgerMenu>

src/MahApps.Metro.Demo_v2/Themes/DemoView.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=NavigateToOnlineDocs}"
4747
CommandParameter="{TemplateBinding HyperlinkOnlineDocs}"
4848
DockPanel.Dock="Right"
49+
Foreground="White"
50+
ToolTip="{TemplateBinding HyperlinkOnlineDocs}"
4951
Style="{StaticResource MahApps.Styles.Button.WindowCommands}" />
5052
<ContentControl Content="{TemplateBinding Header}"
5153
Margin="5,0"

src/MahApps.Metro.Demo_v2/Themes/DemoViewDataTemplates.xaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,26 @@
88
<mah:NumericUpDown Speedup="True" Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
99
</DataTemplate>
1010

11-
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.Boolean">
11+
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.Boolean" DataType="{x:Type ctrls:DemoViewProperty}">
1212
<mah:ToggleSwitch OnContent="True" OffContent="False" IsOn="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
1313
</DataTemplate>
1414

15-
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.String">
15+
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.String" DataType="{x:Type ctrls:DemoViewProperty}">
1616
<TextBox Text="{Binding Value, Mode=TwoWay}" />
1717
</DataTemplate>
1818

19-
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.Enum">
19+
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.Enum" DataType="{x:Type ctrls:DemoViewProperty}">
2020
<ComboBox IsEditable="False"
2121
ItemsSource="{Binding Value, Converter={conv:EnumToItemSourceConverter}}"
2222
SelectedItem="{Binding Value, Mode=TwoWay}" />
2323
</DataTemplate>
24+
25+
<DataTemplate x:Key="MahDemo.DataTemplates.PropertyPresenter.Styles" DataType="{x:Type ctrls:DemoViewProperty}">
26+
<ComboBox IsEditable="False"
27+
ItemsSource="{Binding ItemSource}"
28+
SelectedValue="{Binding Value, Mode=TwoWay}"
29+
SelectedValuePath="Value"
30+
DisplayMemberPath="Key" />
31+
</DataTemplate>
32+
2433
</ResourceDictionary>

0 commit comments

Comments
 (0)