Last active
January 22, 2016 13:19
-
-
Save devlights/0f6789bee71fa32baee9 to your computer and use it in GitHub Desktop.
[WPF] DataGridの見た目などを共有してデータのみ実行時に指定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Window x:Class="WpfApplication1.MainWindow" | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
| Title="MainWindow" Height="350" Width="600"> | |
| <Window.Resources> | |
| <DataGrid x:Key="パターン1" x:Shared="False" AutoGenerateColumns="False" ItemsSource="{Binding .}"> | |
| <DataGrid.Columns> | |
| <DataGridTemplateColumn Header="名前"> | |
| <DataGridTemplateColumn.CellTemplate> | |
| <DataTemplate> | |
| <Border> | |
| <TextBlock Text="{Binding Name}"></TextBlock> | |
| </Border> | |
| </DataTemplate> | |
| </DataGridTemplateColumn.CellTemplate> | |
| </DataGridTemplateColumn> | |
| <DataGridTemplateColumn Header="年齢"> | |
| <DataGridTemplateColumn.CellTemplate> | |
| <DataTemplate> | |
| <Border> | |
| <TextBlock Text="{Binding Age}"></TextBlock> | |
| </Border> | |
| </DataTemplate> | |
| </DataGridTemplateColumn.CellTemplate> | |
| </DataGridTemplateColumn> | |
| </DataGrid.Columns> | |
| </DataGrid> | |
| <DataGrid x:Key="パターン2" AutoGenerateColumns="False" ItemsSource="{Binding .}"> | |
| <DataGrid.Columns> | |
| <DataGridTemplateColumn Header="仕事" Width="100"> | |
| <DataGridTemplateColumn.CellTemplate> | |
| <DataTemplate> | |
| <Border> | |
| <TextBlock Text="{Binding jobName}"></TextBlock> | |
| </Border> | |
| </DataTemplate> | |
| </DataGridTemplateColumn.CellTemplate> | |
| </DataGridTemplateColumn> | |
| <DataGridTemplateColumn Header="日時"> | |
| <DataGridTemplateColumn.CellTemplate> | |
| <DataTemplate> | |
| <Border> | |
| <TextBlock Text="{Binding arrived}"></TextBlock> | |
| </Border> | |
| </DataTemplate> | |
| </DataGridTemplateColumn.CellTemplate> | |
| </DataGridTemplateColumn> | |
| </DataGrid.Columns> | |
| </DataGrid> | |
| </Window.Resources> | |
| <Grid> | |
| <Grid.ColumnDefinitions> | |
| <ColumnDefinition Width="260*"/> | |
| <ColumnDefinition Width="257*"/> | |
| </Grid.ColumnDefinitions> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="31*"/> | |
| <RowDefinition Height="31*"/> | |
| <RowDefinition Height="31*"/> | |
| </Grid.RowDefinitions> | |
| <ContentControl Grid.Row="0" Grid.Column="0" Content="{StaticResource パターン1}" DataContext="{Binding MyItems}"></ContentControl> | |
| <ContentControl Grid.Row="1" Grid.Column="0" Content="{StaticResource パターン1}" DataContext="{Binding MyItems2}"></ContentControl> | |
| <ContentControl Grid.Row="2" Grid.Column="0" Content="{StaticResource パターン1}" DataContext="{Binding MyItems3}"></ContentControl> | |
| <ContentControl Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" Content="{StaticResource パターン2}" DataContext="{Binding MyItems4}"></ContentControl> | |
| </Grid> | |
| </Window> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/5716123/wpf-datagrid-columns-in-style-or-resource
http://stackoverflow.com/questions/5731276/wpf-contentcontrol-styling