--- lang: ja-jp breaks: true --- # WPF DataGrid に `MaterialDesignThemes` を適用する 2022-08-30  ## 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="MaterialDesignThemes" Version="4.6.0-ci277" /> </ItemGroup> </Project> ``` ## App.xaml ```xaml= <Application x:Class="WPF_MaterialDesignThemes_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_MaterialDesignThemes_DataGrid" StartupUri="MainWindow.xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" > <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" /> <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> ``` ## MainWindow.xaml ```xaml= <Window x:Class="WPF_MaterialDesignThemes_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_MaterialDesignThemes_DataGrid" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" 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" materialDesign:DataGridAssist.SelectedCellBorderBrush="Crimson" /> </Grid> </Window> ``` ###### tags: `WPF` `DataGrid` `MaterialDesignThemes`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up