diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.NET40/MahApps.Metro.Demo.NET40.csproj b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.NET40/MahApps.Metro.Demo.NET40.csproj index b818977b5b..97a6187ba9 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.NET40/MahApps.Metro.Demo.NET40.csproj +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.NET40/MahApps.Metro.Demo.NET40.csproj @@ -1,4 +1,4 @@ - + @@ -255,4 +255,4 @@ - \ No newline at end of file + diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/SelectionExamples.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/SelectionExamples.xaml index 392b4af1ac..e156b62286 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/SelectionExamples.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/SelectionExamples.xaml @@ -208,6 +208,62 @@ Text="{Binding Path=Title, Mode=TwoWay}" /> + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/ComboDataGrid.cs b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/ComboDataGrid.cs new file mode 100644 index 0000000000..c12786304a --- /dev/null +++ b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/ComboDataGrid.cs @@ -0,0 +1,74 @@ +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace MahApps.Metro.Controls +{ + [TemplatePart(Name = "PART_DataGrid", Type = typeof(DataGrid))] + public class ComboDataGrid : ComboBox + { + private readonly ObservableCollection columns; + private DataGrid dataGrid; + + static ComboDataGrid() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboDataGrid), new FrameworkPropertyMetadata(typeof(ComboDataGrid))); + } + + public ComboDataGrid() + { + this.columns = new ObservableCollection(); + this.columns.CollectionChanged += this.OnColumnsCollectionChanged; + } + + public static readonly DependencyProperty AutoGenerateColumnsProperty = DependencyProperty.Register("AutoGenerateColumns", typeof(bool), typeof(ComboDataGrid), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + + public bool AutoGenerateColumns + { + get { return (bool)GetValue(AutoGenerateColumnsProperty); } + set { SetValue(AutoGenerateColumnsProperty, value); } + } + + public ObservableCollection Columns + { + get { return this.columns; } + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + this.dataGrid = (DataGrid)this.GetTemplateChild("PART_DataGrid"); + if (dataGrid == null) + { + return; + } + this.dataGrid.MouseLeftButtonUp += this.OnDataGridMouseLeftButtonUp; + this.UpdateDataGridColumns(); + } + + private void OnColumnsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (this.dataGrid != null) + { + this.UpdateDataGridColumns(); + } + } + + private void OnDataGridMouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + this.IsDropDownOpen = false; + } + + private void UpdateDataGridColumns() + { + this.dataGrid.Columns.Clear(); + foreach (DataGridColumn column in this.Columns) + { + column.IsReadOnly = true; + this.dataGrid.Columns.Add(column); + } + } + } +} diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems b/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems index 17ecb16ae4..7aa99e998a 100644 --- a/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems +++ b/src/MahApps.Metro/MahApps.Metro.Shared/MahApps.Metro.Shared.projitems @@ -28,6 +28,7 @@ + diff --git a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj index 932b9090a6..7c52435217 100644 --- a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj +++ b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj @@ -404,6 +404,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj index 3898758e78..b59c8cb479 100644 --- a/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj +++ b/src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj @@ -404,6 +404,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/src/MahApps.Metro/MahApps.Metro/Styles/Controls.ComboBox.xaml b/src/MahApps.Metro/MahApps.Metro/Styles/Controls.ComboBox.xaml index a5350bfebb..17c66b71de 100644 --- a/src/MahApps.Metro/MahApps.Metro/Styles/Controls.ComboBox.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Styles/Controls.ComboBox.xaml @@ -12,7 +12,8 @@ diff --git a/src/MahApps.Metro/MahApps.Metro/Themes/ComboDataGrid.xaml b/src/MahApps.Metro/MahApps.Metro/Themes/ComboDataGrid.xaml new file mode 100644 index 0000000000..34a7194195 --- /dev/null +++ b/src/MahApps.Metro/MahApps.Metro/Themes/ComboDataGrid.xaml @@ -0,0 +1,688 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml b/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml index 1b527b97b3..31a64319c2 100644 --- a/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Themes/Generic.xaml @@ -36,6 +36,7 @@ +