Skip to content
Merged
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
52 changes: 52 additions & 0 deletions src/MainDemo.Wpf/DataGrids.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,58 @@
CanUserAddRows="False"
ItemsSource="{Binding Items4}" />
</smtx:XamlDisplay>

<Rectangle Style="{StaticResource PageSectionSeparator}" />

<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Custom row height" />

<smtx:XamlDisplay UniqueKey="grids_5">
<DataGrid AutoGenerateColumns="False"
IsReadOnly="True"
ItemsSource="{Binding Items1}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Actions">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Command="{Binding DataContext.EditItemCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
CommandParameter="{Binding .}"
Content="{materialDesign:PackIcon Kind=Pen}"
Style="{StaticResource MaterialDesignIconButton}"
ToolTip="Edit">
<Button.Resources>
<SolidColorBrush x:Key="MaterialDesign.Brush.Primary" Color="Orange" />
</Button.Resources>
</Button>
<Button Command="{Binding DataContext.DuplicateItemCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
CommandParameter="{Binding .}"
Content="{materialDesign:PackIcon Kind=ContentDuplicate}"
Style="{StaticResource MaterialDesignIconButton}"
ToolTip="Duplicate">
<Button.Resources>
<SolidColorBrush x:Key="MaterialDesign.Brush.Primary" Color="DodgerBlue" />
</Button.Resources>
</Button>
<Button Command="{Binding DataContext.DeleteItemCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
CommandParameter="{Binding .}"
Content="{materialDesign:PackIcon Kind=Bin}"
Style="{StaticResource MaterialDesignIconButton}"
ToolTip="Delete">
<Button.Resources>
<SolidColorBrush x:Key="MaterialDesign.Brush.Primary" Color="Red" />
</Button.Resources>
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Code}" Header="Code" />
<DataGridTextColumn Binding="{Binding Name}" Header="Name" />
<DataGridTextColumn Binding="{Binding Description}" Header="Description" />
</DataGrid.Columns>
</DataGrid>
</smtx:XamlDisplay>

</StackPanel>
</UserControl>

2 changes: 1 addition & 1 deletion src/MainDemo.Wpf/DataGrids.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class DataGrids
{
public DataGrids()
{
DataContext = new ListsAndGridsViewModel();
DataContext = new ListsAndGridsViewModel(MainWindow.Snackbar.MessageQueue!);
InitializeComponent();
}
}
33 changes: 25 additions & 8 deletions src/MainDemo.Wpf/Domain/ListsAndGridsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using MaterialDesignDemo.Shared.Domain;
using MaterialDesignThemes.Wpf;

namespace MaterialDesignDemo.Domain;

public class ListsAndGridsViewModel : ViewModelBase
public partial class ListsAndGridsViewModel : ViewModelBase
{
public ListsAndGridsViewModel()
private readonly ISnackbarMessageQueue _snackbarMessageQueue;

public ListsAndGridsViewModel(ISnackbarMessageQueue snackbarMessageQueue)
{
_snackbarMessageQueue = snackbarMessageQueue;
Items1 = CreateData();
Items2 = CreateData();
Items3 = CreateData();
Expand All @@ -21,7 +26,7 @@ public ListsAndGridsViewModel()
};
}

Files = new List<string>();
Files = [];

for (int i = 0; i < 1000; i++)
{
Expand Down Expand Up @@ -56,8 +61,8 @@ private static void SelectAll(bool select, IEnumerable<SelectableViewModel> mode

private static ObservableCollection<SelectableViewModel> CreateData()
{
return new ObservableCollection<SelectableViewModel>
{
return
[
new SelectableViewModel
{
Code = 'M',
Expand All @@ -77,17 +82,29 @@ private static ObservableCollection<SelectableViewModel> CreateData()
Name = "Predator",
Description = "If it bleeds, we can kill it"
}
};
];
}

public ObservableCollection<SelectableViewModel> Items1 { get; }
public ObservableCollection<SelectableViewModel> Items2 { get; }
public ObservableCollection<SelectableViewModel> Items3 { get; }
public ObservableCollection<SelectableViewModel> Items4 { get; }

public IEnumerable<string> Foods => new[] { "Burger", "Fries", "Shake", "Lettuce" };
public IEnumerable<string> Foods => ["Burger", "Fries", "Shake", "Lettuce"];

public IList<string> Files { get; }

public IEnumerable<DataGridSelectionUnit> SelectionUnits => new[] { DataGridSelectionUnit.FullRow, DataGridSelectionUnit.Cell, DataGridSelectionUnit.CellOrRowHeader };
public IEnumerable<DataGridSelectionUnit> SelectionUnits => [DataGridSelectionUnit.FullRow, DataGridSelectionUnit.Cell, DataGridSelectionUnit.CellOrRowHeader];

[RelayCommand]
private void EditItem(SelectableViewModel item)
=> _snackbarMessageQueue.Enqueue($"Editing {item.Name}");

[RelayCommand]
private void DuplicateItem(SelectableViewModel item)
=> _snackbarMessageQueue.Enqueue($"Duplicating {item.Name}");

[RelayCommand]
private void DeleteItem(SelectableViewModel item)
=> _snackbarMessageQueue.Enqueue($"Deleting {item.Name}");
}
2 changes: 1 addition & 1 deletion src/MainDemo.Wpf/Lists.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class Lists
{
public Lists()
{
DataContext = new ListsAndGridsViewModel();
DataContext = new ListsAndGridsViewModel(MainWindow.Snackbar.MessageQueue!);
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,16 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True" />
<ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<ContentPresenter Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=(wpf:DataGridAssist.SelectedCellBorderBrush)}" />
Expand Down Expand Up @@ -381,7 +385,7 @@
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Control SnapsToDevicePixels="false"
Template="{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},FallbackValue={x:Null}}"
Template="{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, FallbackValue={x:Null}}"
Visibility="{Binding (Validation.HasError), Converter={x:Static converters:BooleanToVisibilityConverter.CollapsedInstance}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, FallbackValue=Collapsed}" />
</StackPanel>
</Border>
Expand Down Expand Up @@ -489,7 +493,9 @@
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding wpf:DataGridAssist.CornerRadius}"
SnapsToDevicePixels="True">
<ScrollViewer x:Name="DG_ScrollViewer" Focusable="false" wpf:ScrollViewerAssist.BubbleVerticalScroll="{Binding Path=(wpf:ScrollViewerAssist.BubbleVerticalScroll), RelativeSource={RelativeSource TemplatedParent}}">
<ScrollViewer x:Name="DG_ScrollViewer"
wpf:ScrollViewerAssist.BubbleVerticalScroll="{Binding Path=(wpf:ScrollViewerAssist.BubbleVerticalScroll), RelativeSource={RelativeSource TemplatedParent}}"
Focusable="false">
<ScrollViewer.Template>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid>
Expand Down
Loading