---
# System prepended metadata

title: WPF DataGrid に `MahApps.Metro` を適用する 2022-08-30
tags: [WPF, DataGrid, MahApps.Metro]

---

---
lang: ja-jp
breaks: true
---
# WPF DataGrid に `MahApps.Metro` を適用する 2022-08-30

![](https://i.imgur.com/IQjiKa8.png)

## csproj

```xml=
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net7.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MahApps.Metro" Version="2.4.9" />
  </ItemGroup>

</Project>
```

## App.xaml

```xaml=
<Application x:Class="WPF_MahApps.Metro_DataGrid.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WPF_MahApps.Metro_DataGrid"
             StartupUri="MainWindow.xaml"
             
            xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
             >
    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <!-- Theme setting -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        
    </Application.Resources>
</Application>
```

## MainWindow.xaml

```xaml=
<Window x:Class="WPF_MahApps.Metro_DataGrid.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF_MahApps.Metro_DataGrid"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
        
        FontFamily="Meiryo UI" FontSize="12"
        >

    <Window.DataContext>
        <viewModels:PostalCodeViewModel />
    </Window.DataContext>

    <Grid>

        <DataGrid
            ItemsSource="{Binding PostalCode_IEnumerable_PostalCodeRow, IsAsync=True}" 
            
            AutoGenerateColumns="True"
            AutoGeneratingColumn="DataGrid_AutoGeneratingColumn"
                
            VirtualizingStackPanel.IsVirtualizing="True"
            VirtualizingStackPanel.VirtualizationMode="Standard" 
            
            EnableColumnVirtualization="True"
            EnableRowVirtualization="True"
            
            CanUserAddRows="False"
            CanUserDeleteRows="False"
            
            CanUserReorderColumns="True"
            CanUserResizeRows="True"
            CanUserSortColumns="True"
            
            SelectionMode="Extended"
            SelectionUnit="FullRow"
            
            ScrollViewer.PanningMode="VerticalOnly"
            ScrollViewer.IsDeferredScrollingEnabled="True"
            ScrollViewer.VerticalScrollBarVisibility="Visible"
            ScrollViewer.HorizontalScrollBarVisibility="Visible"
                
            />

    </Grid>
</Window>

```


###### tags: `WPF` `DataGrid` `MahApps.Metro`
