From 11e04fb321144296f8d5b848dbccc12a2a6f86be Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 28 May 2020 14:45:01 +0200 Subject: [PATCH 1/5] Init new demo App --- src/MahApps.Metro.Demo_v2/App.xaml | 34 ++++ src/MahApps.Metro.Demo_v2/App.xaml.cs | 17 ++ src/MahApps.Metro.Demo_v2/AssemblyInfo.cs | 10 + .../Controls/DemoView.cs | 92 +++++++++ .../Controls/DemoViewProperty.cs | 192 ++++++++++++++++++ .../DemoViewPropertyTemplateSelector.cs | 27 +++ .../Converter/EnumToItemSourceConverter.cs | 27 +++ .../Core/SimpleCommand.cs | 39 ++++ .../ExampleViews/NumericUpDownExample.xaml | 39 ++++ .../ExampleViews/NumericUpDownExample.xaml.cs | 44 ++++ .../MahApps.Metro.Demo_v2.csproj | 19 ++ src/MahApps.Metro.Demo_v2/MainWindow.xaml | 57 ++++++ src/MahApps.Metro.Demo_v2/MainWindow.xaml.cs | 29 +++ .../Themes/DemoView.xaml | 152 ++++++++++++++ .../Themes/DemoViewDataTemplates.xaml | 24 +++ src/MahApps.Metro.sln | 6 + 16 files changed, 808 insertions(+) create mode 100644 src/MahApps.Metro.Demo_v2/App.xaml create mode 100644 src/MahApps.Metro.Demo_v2/App.xaml.cs create mode 100644 src/MahApps.Metro.Demo_v2/AssemblyInfo.cs create mode 100644 src/MahApps.Metro.Demo_v2/Controls/DemoView.cs create mode 100644 src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs create mode 100644 src/MahApps.Metro.Demo_v2/Controls/DemoViewPropertyTemplateSelector.cs create mode 100644 src/MahApps.Metro.Demo_v2/Converter/EnumToItemSourceConverter.cs create mode 100644 src/MahApps.Metro.Demo_v2/Core/SimpleCommand.cs create mode 100644 src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml create mode 100644 src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml.cs create mode 100644 src/MahApps.Metro.Demo_v2/MahApps.Metro.Demo_v2.csproj create mode 100644 src/MahApps.Metro.Demo_v2/MainWindow.xaml create mode 100644 src/MahApps.Metro.Demo_v2/MainWindow.xaml.cs create mode 100644 src/MahApps.Metro.Demo_v2/Themes/DemoView.xaml create mode 100644 src/MahApps.Metro.Demo_v2/Themes/DemoViewDataTemplates.xaml diff --git a/src/MahApps.Metro.Demo_v2/App.xaml b/src/MahApps.Metro.Demo_v2/App.xaml new file mode 100644 index 0000000000..cf2ca5d08c --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/App.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + diff --git a/src/MahApps.Metro.Demo_v2/App.xaml.cs b/src/MahApps.Metro.Demo_v2/App.xaml.cs new file mode 100644 index 0000000000..03b9b7ff63 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace MahApps.Metro.Demo_v2 +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/src/MahApps.Metro.Demo_v2/AssemblyInfo.cs b/src/MahApps.Metro.Demo_v2/AssemblyInfo.cs new file mode 100644 index 0000000000..8b5504ecfb --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs b/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs new file mode 100644 index 0000000000..9e0d9a43d8 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs @@ -0,0 +1,92 @@ +using ICSharpCode.AvalonEdit; +using MahApps.Demo.Core; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace MahApps.Demo.Controls +{ + [TemplatePart(Name = nameof(PART_AvalonEdit), Type = typeof(TextEditor))] + public class DemoView : HeaderedContentControl + { + private TextEditor PART_AvalonEdit; + + /// Identifies the dependency property. + public static readonly DependencyProperty ExampleXamlProperty = DependencyProperty.Register(nameof(ExampleXaml), typeof(string), typeof(DemoView), new PropertyMetadata(null)); + + /// Identifies the dependency property. + public static readonly DependencyProperty HyperlinkOnlineDocsProperty = DependencyProperty.Register(nameof(HyperlinkOnlineDocs), typeof(string), typeof(DemoView), new PropertyMetadata(null)); + + + + public DemoView() + { + DemoProperties.CollectionChanged += DemoProperties_CollectionChanged; + } + + public ObservableCollection DemoProperties { get; } = new ObservableCollection(); + + private void DemoProperties_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + if (e.NewItems != null) + { + foreach (DemoViewProperty item in e.NewItems) + { + item.PropertyChanged += DemoProperties_ItemPropertyChanged; + } + } + if (e.OldItems != null) + { + foreach (DemoViewProperty item in e.OldItems) + { + item.PropertyChanged -= DemoProperties_ItemPropertyChanged; + } + } + } + + private void DemoProperties_ItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + SetExampleXaml(); + } + + + + public string ExampleXaml + { + get { return (string)GetValue(ExampleXamlProperty); } + set { SetValue(ExampleXamlProperty, value); } + } + + private void SetExampleXaml() + { + if (PART_AvalonEdit != null) + { + PART_AvalonEdit.Text = ExampleXaml; + } + } + + public string HyperlinkOnlineDocs + { + get { return (string)GetValue(HyperlinkOnlineDocsProperty); } + set { SetValue(HyperlinkOnlineDocsProperty, value); } + } + + public SimpleCommand NavigateToOnlineDocs { get; } = new SimpleCommand( + (param) => !string.IsNullOrEmpty(param?.ToString()), + (param) => Process.Start(new ProcessStartInfo(param?.ToString()))); + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + PART_AvalonEdit = GetTemplateChild(nameof(PART_AvalonEdit)) as TextEditor; + } + + } +} diff --git a/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs b/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs new file mode 100644 index 0000000000..e7146714ea --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs @@ -0,0 +1,192 @@ +using MahApps.Metro.Demo_v2; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace MahApps.Demo.Controls +{ + public class DemoViewProperty : DependencyObject, INotifyPropertyChanged + { + #region PropertyChanged + public event PropertyChangedEventHandler PropertyChanged; + + public void RaisePropertyChanged(string PropertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(PropertyName)); + } + + private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is DemoViewProperty demoViewProperty) + { + demoViewProperty.RaisePropertyChanged(e.Property.Name); + } + } + + #endregion + + + #region Constructors + + public DemoViewProperty() + { + + } + + public DemoViewProperty(DependencyProperty dependencyProperty, DependencyObject bindingTarget, string groupName = null, DataTemplate dataTemplate = null) + { + SetCurrentValue(PropertyNameProperty, GetDefaultPropertyName(dependencyProperty)); + + SetCurrentValue(GroupNameProperty, groupName ?? GetDefaultGroupName()); + + SetCurrentValue(DataTemplateProperty, dataTemplate ?? GetDefaultDataTemplate(dependencyProperty)); + + // Create Binding to the Control + var binding = new Binding() + { + Path = new PropertyPath(dependencyProperty), + Source = bindingTarget, + Mode = BindingMode.TwoWay + }; + BindingOperations.SetBinding(this, DemoViewProperty.ValueProperty, binding); + + } + #endregion + + + /// Identifies the dependency property. + public static readonly DependencyProperty PropertyNameProperty = DependencyProperty.Register(nameof(PropertyName), typeof(string), typeof(DemoViewProperty), new PropertyMetadata(null)); + + /// Identifies the dependency property. + public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(object), typeof(DemoViewProperty), new PropertyMetadata(null, OnValueChanged)); + + /// Identifies the dependency property. + public static readonly DependencyProperty DataTemplateProperty = DependencyProperty.Register(nameof(DataTemplate), typeof(DataTemplate), typeof(DemoViewProperty), new PropertyMetadata(null)); + + /// Identifies the dependency property. + public static readonly DependencyProperty ItemSourceProperty = DependencyProperty.Register(nameof(ItemSource), typeof(IEnumerable), typeof(DemoViewProperty), new PropertyMetadata(null)); + + /// Identifies the dependency property. + public static readonly DependencyProperty GroupNameProperty = DependencyProperty.Register(nameof(GroupName), typeof(string), typeof(DemoViewProperty), new PropertyMetadata(null)); + + + + /// + /// Gets or Sets the PropertyName + /// + public string PropertyName + { + get { return (string)GetValue(PropertyNameProperty); } + set { SetValue(PropertyNameProperty, value); } + } + + private string GetDefaultPropertyName(DependencyProperty dependencyProperty) + { + if (typeof(UIElement).IsAssignableFrom(dependencyProperty.OwnerType)) + { + return dependencyProperty.Name; + } + else + { + return $"{dependencyProperty.OwnerType.Name}.{dependencyProperty.Name}"; + } + + } + + /// + /// Gets or Sets the Value + /// + public object Value + { + get { return (object)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + + + /// + /// Gets or Sets the GroupName + /// + public string GroupName + { + get { return (string)GetValue(GroupNameProperty); } + set { SetValue(GroupNameProperty, value); } + } + + private string GetDefaultGroupName() + { + if (string.IsNullOrWhiteSpace(PropertyName)) + return null; + + switch (this.PropertyName) + { + case string _ when PropertyName.EndsWith("Alignment"): + case string _ when PropertyName.EndsWith("Height"): + case string _ when PropertyName.EndsWith("Width"): + return "Layout"; + + default: + return "Misc"; + } + } + + /// + /// Gets or Sets the DataTemplate + /// + public DataTemplate DataTemplate + { + get { return (DataTemplate)GetValue(DataTemplateProperty); } + set { SetValue(DataTemplateProperty, value); } + } + + private DataTemplate GetDefaultDataTemplate(DependencyProperty dependencyProperty) + { + // Numeric + if (dependencyProperty.PropertyType.IsAssignableFrom(typeof(sbyte)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(byte)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(short)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(ushort)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(int)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(uint)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(long)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(ulong)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(float)) || + dependencyProperty.PropertyType.IsAssignableFrom(typeof(double)) || + dependencyProperty.PropertyType. IsAssignableFrom(typeof(decimal))) + { + return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Numeric"] as DataTemplate; + } + + if (dependencyProperty.PropertyType.IsAssignableFrom(typeof(string))) + { + return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.String"] as DataTemplate; + } + + if (dependencyProperty.PropertyType == typeof(bool)) + { + return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Boolean"] as DataTemplate; + } + + if (dependencyProperty.PropertyType.IsEnum) + { + return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Enum"] as DataTemplate; + } + + return null; + } + + /// + /// Gets or Sets the ItemSource used for selectable + /// + public IEnumerable ItemSource + { + get { return (IEnumerable)GetValue(ItemSourceProperty); } + set { SetValue(ItemSourceProperty, value); } + } + + } +} diff --git a/src/MahApps.Metro.Demo_v2/Controls/DemoViewPropertyTemplateSelector.cs b/src/MahApps.Metro.Demo_v2/Controls/DemoViewPropertyTemplateSelector.cs new file mode 100644 index 0000000000..df6a562126 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Controls/DemoViewPropertyTemplateSelector.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace MahApps.Demo.Controls +{ + public class DemoViewPropertyTemplateSelector : DataTemplateSelector + { + public DataTemplate FallbackTemplate { get; set; } + + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + if (item is DemoViewProperty demoProperty) + { + return demoProperty.DataTemplate ?? FallbackTemplate; + } + else + { + return FallbackTemplate; + } + } + } +} diff --git a/src/MahApps.Metro.Demo_v2/Converter/EnumToItemSourceConverter.cs b/src/MahApps.Metro.Demo_v2/Converter/EnumToItemSourceConverter.cs new file mode 100644 index 0000000000..45d6706150 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Converter/EnumToItemSourceConverter.cs @@ -0,0 +1,27 @@ +using MahApps.Metro.Converters; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MahApps.Demo.Converter +{ + public class EnumToItemSourceConverter : MarkupConverter + { + protected override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is Enum) + { + return Enum.GetValues(value.GetType()); + } + throw new ArgumentException("the provided value is not a valid Enum"); + } + + protected override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } + } +} diff --git a/src/MahApps.Metro.Demo_v2/Core/SimpleCommand.cs b/src/MahApps.Metro.Demo_v2/Core/SimpleCommand.cs new file mode 100644 index 0000000000..bc7d052014 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Core/SimpleCommand.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace MahApps.Demo.Core +{ + public class SimpleCommand : ICommand + { + public SimpleCommand(Func canExecute = null, Action execute = null) + { + this.CanExecuteDelegate = canExecute; + this.ExecuteDelegate = execute; + } + + public Func CanExecuteDelegate { get; set; } + + public Action ExecuteDelegate { get; set; } + + public bool CanExecute(object parameter) + { + var canExecute = this.CanExecuteDelegate; + return canExecute == null || canExecute(parameter); + } + + public event EventHandler CanExecuteChanged + { + add => CommandManager.RequerySuggested += value; + remove => CommandManager.RequerySuggested -= value; + } + + public void Execute(object parameter) + { + this.ExecuteDelegate?.Invoke(parameter); + } + } +} diff --git a/src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml b/src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml new file mode 100644 index 0000000000..19a8eb9bfd --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml @@ -0,0 +1,39 @@ + + + ]]> + + + + diff --git a/src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml.cs b/src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml.cs new file mode 100644 index 0000000000..7734405d01 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/ExampleViews/NumericUpDownExample.xaml.cs @@ -0,0 +1,44 @@ +using MahApps.Demo.Controls; +using MahApps.Metro.Controls; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace MahApps.Demo.ExampleViews +{ + /// + /// Interaction logic for NumericUpDownExample.xaml + /// + public partial class NumericUpDownExample : UserControl + { + public NumericUpDownExample() + { + InitializeComponent(); + + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.ValueProperty, numericUpDown, "NumericUpDown")); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.NumericInputModeProperty, numericUpDown)); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.WidthProperty, numericUpDown)); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.HeightProperty, numericUpDown)); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.HorizontalAlignmentProperty, numericUpDown)); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.VerticalAlignmentProperty, numericUpDown)); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.StringFormatProperty, numericUpDown, "NumericUpDown")); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.IntervalProperty, numericUpDown, "NumericUpDown")); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.InterceptArrowKeysProperty, numericUpDown, "NumericUpDown")); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.InterceptManualEnterProperty, numericUpDown, "NumericUpDown")); + demoView.DemoProperties.Add(new DemoViewProperty(NumericUpDown.InterceptMouseWheelProperty, numericUpDown, "NumericUpDown")); + + demoView.DemoProperties.Add(new DemoViewProperty(TextBoxHelper.ClearTextButtonProperty, numericUpDown, "Attached")); + } + } +} diff --git a/src/MahApps.Metro.Demo_v2/MahApps.Metro.Demo_v2.csproj b/src/MahApps.Metro.Demo_v2/MahApps.Metro.Demo_v2.csproj new file mode 100644 index 0000000000..38ef058b3c --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/MahApps.Metro.Demo_v2.csproj @@ -0,0 +1,19 @@ + + + + WinExe + netcoreapp3.1 + true + MahApps.Demo + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MahApps.Metro.Demo_v2/MainWindow.xaml b/src/MahApps.Metro.Demo_v2/MainWindow.xaml new file mode 100644 index 0000000000..82d1140b41 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/MainWindow.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/MahApps.Metro.Demo_v2/MainWindow.xaml.cs b/src/MahApps.Metro.Demo_v2/MainWindow.xaml.cs new file mode 100644 index 0000000000..38a052ee45 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/MainWindow.xaml.cs @@ -0,0 +1,29 @@ +using MahApps.Metro.Controls; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace MahApps.Demo +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : MetroWindow + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/src/MahApps.Metro.Demo_v2/Themes/DemoView.xaml b/src/MahApps.Metro.Demo_v2/Themes/DemoView.xaml new file mode 100644 index 0000000000..f3ddd59c7d --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Themes/DemoView.xaml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MahApps.Metro.Demo_v2/Themes/DemoViewDataTemplates.xaml b/src/MahApps.Metro.Demo_v2/Themes/DemoViewDataTemplates.xaml new file mode 100644 index 0000000000..99025a0055 --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/Themes/DemoViewDataTemplates.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MahApps.Metro.sln b/src/MahApps.Metro.sln index 9110c970ed..eafabb1586 100644 --- a/src/MahApps.Metro.sln +++ b/src/MahApps.Metro.sln @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\NuGet.Config = ..\NuGet.Config EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MahApps.Metro.Demo_v2", "MahApps.Metro.Demo_v2\MahApps.Metro.Demo_v2.csproj", "{1DB58E6F-431B-4360-A66F-BF6A51C8BE02}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,6 +44,10 @@ Global {40048BCF-D1C7-46CC-B781-05718BE25BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU {40048BCF-D1C7-46CC-B781-05718BE25BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU {40048BCF-D1C7-46CC-B781-05718BE25BFC}.Release|Any CPU.Build.0 = Release|Any CPU + {1DB58E6F-431B-4360-A66F-BF6A51C8BE02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DB58E6F-431B-4360-A66F-BF6A51C8BE02}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DB58E6F-431B-4360-A66F-BF6A51C8BE02}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DB58E6F-431B-4360-A66F-BF6A51C8BE02}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 62a368a86931f6f25e81e8741c4ebaafecaad435 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 28 May 2020 15:20:59 +0200 Subject: [PATCH 2/5] Added a way to access the different Styles --- .../Controls/DemoViewProperty.cs | 17 +++++-- .../ExampleViews/ButtonExample.xaml | 29 ++++++++++++ .../ExampleViews/ButtonExample.xaml.cs | 44 +++++++++++++++++++ .../ExampleViews/NumericUpDownExample.xaml.cs | 1 + src/MahApps.Metro.Demo_v2/MainWindow.xaml | 10 +++++ .../Themes/DemoView.xaml | 2 + .../Themes/DemoViewDataTemplates.xaml | 15 +++++-- 7 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 src/MahApps.Metro.Demo_v2/ExampleViews/ButtonExample.xaml create mode 100644 src/MahApps.Metro.Demo_v2/ExampleViews/ButtonExample.xaml.cs diff --git a/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs b/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs index e7146714ea..933066aa2c 100644 --- a/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs +++ b/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs @@ -1,5 +1,6 @@ using MahApps.Metro.Demo_v2; using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -69,7 +70,7 @@ public DemoViewProperty(DependencyProperty dependencyProperty, DependencyObject public static readonly DependencyProperty DataTemplateProperty = DependencyProperty.Register(nameof(DataTemplate), typeof(DataTemplate), typeof(DemoViewProperty), new PropertyMetadata(null)); /// Identifies the dependency property. - public static readonly DependencyProperty ItemSourceProperty = DependencyProperty.Register(nameof(ItemSource), typeof(IEnumerable), typeof(DemoViewProperty), new PropertyMetadata(null)); + public static readonly DependencyProperty ItemSourceProperty = DependencyProperty.Register(nameof(ItemSource), typeof(IEnumerable), typeof(DemoViewProperty), new PropertyMetadata(null)); /// Identifies the dependency property. public static readonly DependencyProperty GroupNameProperty = DependencyProperty.Register(nameof(GroupName), typeof(string), typeof(DemoViewProperty), new PropertyMetadata(null)); @@ -145,6 +146,9 @@ public DataTemplate DataTemplate private DataTemplate GetDefaultDataTemplate(DependencyProperty dependencyProperty) { + // Any Object + if (dependencyProperty.PropertyType == typeof(object)) return null; + // Numeric if (dependencyProperty.PropertyType.IsAssignableFrom(typeof(sbyte)) || dependencyProperty.PropertyType.IsAssignableFrom(typeof(byte)) || @@ -156,7 +160,7 @@ private DataTemplate GetDefaultDataTemplate(DependencyProperty dependencyPropert dependencyProperty.PropertyType.IsAssignableFrom(typeof(ulong)) || dependencyProperty.PropertyType.IsAssignableFrom(typeof(float)) || dependencyProperty.PropertyType.IsAssignableFrom(typeof(double)) || - dependencyProperty.PropertyType. IsAssignableFrom(typeof(decimal))) + dependencyProperty.PropertyType.IsAssignableFrom(typeof(decimal))) { return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Numeric"] as DataTemplate; } @@ -176,15 +180,20 @@ dependencyProperty.PropertyType. IsAssignableFrom(typeof(decimal))) return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Enum"] as DataTemplate; } + if (dependencyProperty.PropertyType.IsAssignableFrom(typeof(Style))) + { + return App.Current.Resources["MahDemo.DataTemplates.PropertyPresenter.Styles"] as DataTemplate; + } + return null; } /// /// Gets or Sets the ItemSource used for selectable /// - public IEnumerable ItemSource + public IEnumerable ItemSource { - get { return (IEnumerable)GetValue(ItemSourceProperty); } + get { return (IEnumerable)GetValue(ItemSourceProperty); } set { SetValue(ItemSourceProperty, value); } } diff --git a/src/MahApps.Metro.Demo_v2/ExampleViews/ButtonExample.xaml b/src/MahApps.Metro.Demo_v2/ExampleViews/ButtonExample.xaml new file mode 100644 index 0000000000..c556d048be --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/ExampleViews/ButtonExample.xaml @@ -0,0 +1,29 @@ + + + ]]> + + + + + diff --git a/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml.cs b/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml.cs new file mode 100644 index 0000000000..6de35109de --- /dev/null +++ b/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml.cs @@ -0,0 +1,43 @@ +using MahApps.Demo.Controls; +using MahApps.Metro.Controls; +using MahApps.Metro.Demo_v2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace MahApps.Demo.ExampleViews +{ + /// + /// Interaction logic for BadgedExample.xaml + /// + public partial class BadgedExample : UserControl + { + public BadgedExample() + { + InitializeComponent(); + + demoView.DemoProperties.Add(new DemoViewProperty(Badged.BadgeProperty, badge, "Badged")); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + badge.SetCurrentValue(ControlzEx.BadgedEx.BadgeProperty, (badge.Badge as int? ?? 0) + 1); + } + + private void Button_MouseRightButtonUp(object sender, MouseButtonEventArgs e) + { + badge.SetCurrentValue(ControlzEx.BadgedEx.BadgeProperty, null); + } + } +} diff --git a/src/MahApps.Metro.Demo_v2/MainWindow.xaml b/src/MahApps.Metro.Demo_v2/MainWindow.xaml index 70c350fb0e..a53cb87b31 100644 --- a/src/MahApps.Metro.Demo_v2/MainWindow.xaml +++ b/src/MahApps.Metro.Demo_v2/MainWindow.xaml @@ -44,11 +44,20 @@ + + + + + + + + + From 5d8d5c71a2d983320c6e9057fe2894e60ac4a963 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 31 May 2020 13:06:29 +0200 Subject: [PATCH 4/5] Improve Example XAML - Renders now on initialization - Replaces [PropertyName] with the Value - A custom Converter can be used to provide e.g. {DynamicResoutce AnyKeyHere} --- .../Controls/DemoView.cs | 22 ++++++++++++++++--- .../Controls/DemoViewProperty.cs | 16 +++++++++++--- .../ExampleViews/BadgedExample.xaml | 8 +++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs b/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs index 9e0d9a43d8..cadf980dab 100644 --- a/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs +++ b/src/MahApps.Metro.Demo_v2/Controls/DemoView.cs @@ -18,8 +18,8 @@ public class DemoView : HeaderedContentControl private TextEditor PART_AvalonEdit; /// Identifies the dependency property. - public static readonly DependencyProperty ExampleXamlProperty = DependencyProperty.Register(nameof(ExampleXaml), typeof(string), typeof(DemoView), new PropertyMetadata(null)); - + public static readonly DependencyProperty ExampleXamlProperty = DependencyProperty.Register(nameof(ExampleXaml), typeof(string), typeof(DemoView), new PropertyMetadata(null, OnExampleXamlChanged)); + /// Identifies the dependency property. public static readonly DependencyProperty HyperlinkOnlineDocsProperty = DependencyProperty.Register(nameof(HyperlinkOnlineDocs), typeof(string), typeof(DemoView), new PropertyMetadata(null)); @@ -67,7 +67,22 @@ private void SetExampleXaml() { if (PART_AvalonEdit != null) { - PART_AvalonEdit.Text = ExampleXaml; + var exampleText = ExampleXaml; + + foreach (var item in DemoProperties) + { + exampleText = exampleText.Replace($"[{item.PropertyName}]", item.GetExampleXamlContent()); + } + + PART_AvalonEdit.Text = exampleText; + } + } + + private static void OnExampleXamlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is DemoView demoView) + { + demoView.SetExampleXaml(); } } @@ -86,6 +101,7 @@ public override void OnApplyTemplate() base.OnApplyTemplate(); PART_AvalonEdit = GetTemplateChild(nameof(PART_AvalonEdit)) as TextEditor; + SetExampleXaml(); } } diff --git a/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs b/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs index 933066aa2c..3aa3b0a424 100644 --- a/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs +++ b/src/MahApps.Metro.Demo_v2/Controls/DemoViewProperty.cs @@ -36,10 +36,10 @@ private static void OnValueChanged(DependencyObject d, DependencyPropertyChanged public DemoViewProperty() { - + GetExampleXamlContent = GetExampleXamlContent_Default; } - public DemoViewProperty(DependencyProperty dependencyProperty, DependencyObject bindingTarget, string groupName = null, DataTemplate dataTemplate = null) + public DemoViewProperty(DependencyProperty dependencyProperty, DependencyObject bindingTarget, string groupName = null, DataTemplate dataTemplate = null) : this() { SetCurrentValue(PropertyNameProperty, GetDefaultPropertyName(dependencyProperty)); @@ -68,7 +68,7 @@ public DemoViewProperty(DependencyProperty dependencyProperty, DependencyObject /// Identifies the dependency property. public static readonly DependencyProperty DataTemplateProperty = DependencyProperty.Register(nameof(DataTemplate), typeof(DataTemplate), typeof(DemoViewProperty), new PropertyMetadata(null)); - + /// Identifies the dependency property. public static readonly DependencyProperty ItemSourceProperty = DependencyProperty.Register(nameof(ItemSource), typeof(IEnumerable), typeof(DemoViewProperty), new PropertyMetadata(null)); @@ -197,5 +197,15 @@ public IEnumerable ItemSource set { SetValue(ItemSourceProperty, value); } } + + #region XAML Replace Value + public Func GetExampleXamlContent { get; set; } + + private string GetExampleXamlContent_Default() + { + return Value?.ToString(); + } + #endregion + } } diff --git a/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml b/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml index 0f2584d5d0..7f1040dd05 100644 --- a/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml +++ b/src/MahApps.Metro.Demo_v2/ExampleViews/BadgedExample.xaml @@ -12,12 +12,12 @@ - +