Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ComboDataGrid Control #2965

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -255,4 +255,4 @@
</Choose>
<Import Project="..\..\..\packages\Fody\build\$(__paket__Fody_targets).targets" Condition="Exists('..\..\..\packages\Fody\build\$(__paket__Fody_targets).targets')" Label="Paket" />
<Import Project="..\..\..\packages\Microsoft.Bcl.Build\build\$(__paket__Microsoft_Bcl_Build_targets).targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build\build\$(__paket__Microsoft_Bcl_Build_targets).targets')" Label="Paket" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,62 @@
Text="{Binding Path=Title, Mode=TwoWay}" />
</StackPanel>
</TabItem>
<TabItem Header="ComboDataGrid"
VerticalAlignment="Bottom">
<StackPanel HorizontalAlignment="Left"
Orientation="Vertical">
<Controls:ComboDataGrid ItemsSource="{Binding Artists}"
DisplayMemberPath="Name"
AutoGenerateColumns="False"
Margin="5"
Width="200"
Controls:TextBoxHelper.ClearTextButton="True"
Controls:TextBoxHelper.Watermark="Please select an item...">
<Controls:ComboDataGrid.Columns>
<DataGridTextColumn Header="ID"
Binding="{Binding ArtistId}" />
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
</Controls:ComboDataGrid.Columns>
</Controls:ComboDataGrid>
<Controls:ComboDataGrid ItemsSource="{Binding Artists}"
DisplayMemberPath="Name"
AutoGenerateColumns="True"
Margin="5"
Width="200" />

<Controls:ComboDataGrid ItemsSource="{Binding Artists}"
DisplayMemberPath="Name"
AutoGenerateColumns="False"
Margin="5"
Width="200"
IsEditable="True"
Controls:TextBoxHelper.UseFloatingWatermark="True"
Controls:TextBoxHelper.Watermark="Please select an item...">
<Controls:ComboDataGrid.Columns>
<DataGridTextColumn Header="ID"
Binding="{Binding ArtistId}" />
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
</Controls:ComboDataGrid.Columns>
</Controls:ComboDataGrid>
<Controls:ComboDataGrid ItemsSource="{Binding Artists}"
DisplayMemberPath="Name"
AutoGenerateColumns="False"
Margin="5"
Width="200"
IsEnabled="False"
Controls:TextBoxHelper.UseFloatingWatermark="True"
SelectedIndex="0">
<Controls:ComboDataGrid.Columns>
<DataGridTextColumn Header="ID"
Binding="{Binding ArtistId}" />
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
</Controls:ComboDataGrid.Columns>
</Controls:ComboDataGrid>
</StackPanel>
</TabItem>
</TabControl>

</UserControl>
74 changes: 74 additions & 0 deletions src/MahApps.Metro/MahApps.Metro.Shared/Controls/ComboDataGrid.cs
Original file line number Diff line number Diff line change
@@ -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<DataGridColumn> columns;
private DataGrid dataGrid;

static ComboDataGrid()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboDataGrid), new FrameworkPropertyMetadata(typeof(ComboDataGrid)));
}

public ComboDataGrid()
{
this.columns = new ObservableCollection<DataGridColumn>();
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<DataGridColumn> 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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\ClipBorder.Utils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\CloseCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\ClosingWindowEventHandlerArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\ComboDataGrid.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\CommandHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\ContentControlEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\CustomValidationPopup.cs" />
Expand Down
4 changes: 4 additions & 0 deletions src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\ComboDataGrid.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\ContentControlEx.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
4 changes: 4 additions & 0 deletions src/MahApps.Metro/MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\ComboDataGrid.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\ContentControlEx.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Loading