MainPage.xaml.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using System.Reflection;
- namespace AgScheduler
- {
- public partial class MainPage : UserControl
- {
- public MainPage()
- {
- InitializeComponent();
- this.Loaded += new RoutedEventHandler(MainPage_Loaded);
- var list = DataEntity.Users;
- PropertyInfo[] infos = typeof(UserInfo).GetProperties();
- //var q = (from rec in list
- // select new { Name = rec.名前, Norma = rec.年計, Result = rec.実績 })
- // .ToArray();
- this.DataContext = infos.AsQueryable();
- }
- void MainPage_Loaded(object sender, RoutedEventArgs e)
- {
- PropertyInfo[] infos = typeof(UserInfo).GetProperties();
- this.dataGrid1.RowHeight = 30;
- this.Foreground = new SolidColorBrush(Colors.Red);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- }
- private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- }
- }
- public class hoge
- {
- public string Name { get; set; }
- public double Norma { get; set; }
- public double Result { get; set; }
- }
- }
MainPage.xaml
- <UserControl
- x:Class="AgScheduler.MainPage"
- 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:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
- xmlns:ctrl="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
- mc:Ignorable="d"
- d:DesignHeight="600" d:DesignWidth="800">
- <Grid x:Name="LayoutRoot">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="180" />
- <ColumnDefinition Width="Auto" />
- <ColumnDefinition Width="620*" />
- </Grid.ColumnDefinitions>
- <ctrl:DataGrid Name="dataGrid1"
- ItemsSource="{Binding}" Grid.Column="2" Margin="0" AutoGenerateColumns="True"
- SelectionChanged="dataGrid1_SelectionChanged" />
- <Button Content="Help" Click="Button_Click"/>
- </Grid>
- </UserControl>
DataEntity.cs
- using System;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using System.Collections.Generic;
- using System.Linq;
- namespace AgScheduler
- {
- public class DataEntity
- {
- public static UserInfo CreateUserInfo()
- {
- return new UserInfo()
- {
- ID = 0,
- 実績 = 80,
- 年計 = 1200,
- 名前 = "テスト太郎"
- };
- }
- public static IQueryable<userinfo> Users {
- get
- {
- var list = new List<userinfo>();
- list.AddRange(new UserInfo[]{
- CreateUserInfo(),
- CreateUserInfo(),
- CreateUserInfo(),
- CreateUserInfo(),
- CreateUserInfo(),
- CreateUserInfo(),
- CreateUserInfo(),
- CreateUserInfo()
- });
- return list.AsQueryable();
- }
- set { }
- }
- public static IQueryable<projectinfo> Projects { get; set; }
- }
- public class UserInfo
- {
- public int ID { get; set; }
- public string 名前 { get; set; }
- public double 年計 { get; set; }
- public double 実績 { get; set; }
- }
- public class ProjectInfo
- {
- public int ID { get; set; }
- public string ProjectName { get; set; }
- public double ProjectAmount { get; set; }
- }
- }
- </projectinfo></userinfo></userinfo>
明示的なデータ構造がわかるものじゃないと中身を表示してくれないし、そもそもPropertyInfoは中身を表示してくれない。意味がわからない。無名構造体でも表示はしてくれない。どういうことだ。適応のさせかたのどこかで間違えたことは確かなのだが、どこかわからない。無名構造体が使えないのでは、DataGridに動的にデータを適応しようと思うと困るのだが。
0 件のコメント:
コメントを投稿