Кажется, я не могу понять, как получить данные из wfp в список и связать их с сеткой данных.
Форма xaml отображается нормально
Я создал свойства, я создал класснаследовать базовый класс, который является code360.Я перепробовал много ресурсов онлайн, но не работал для меня.Я попытался жестко запрограммировать ввод, чтобы увидеть, заполнит ли он сетку, но никак не мог.Вот так
{firstName = "Tim", lastName = "Joy",
email = "tim@joy.com",
phoneNumber = "0988390243",
amount = 200000 }
Это mainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Windows;
namespace Code360
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public class code360
{
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public string phoneNumber { get; set; }
public decimal amount { get; set; }
}
public class Code360Manager : List<code360>
{
public Code360Manager()
{
Add(new code360() {firstName = "Tim", lastName = "Joy", email = "tim@joy.com", phoneNumber = "0988390243", amount = 200000 });
}
}
private void SubmitButton_Click(object sender, RoutedEventArgs e)
{
//studentGrid.ItemsSource = Code360Manager();
MessageBox.Show("This is to test the firstname", firstName.Text);
}
}
}
Это mainWindow.xaml
<Window x:Class="Code360.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:Code360"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="1" Grid.Column="1" FontSize="36"
Text="Code360 Student Record" Grid.ColumnSpan="3"
Margin="0,0,0,10" />
<TextBlock Grid.Column="1" Grid.Row="2"
Text="First Name" Margin="0,0,0,10"/>
<TextBox x:Name="firstName" Grid.Column="2" Grid.Row="2"
Width="150" Margin="0,0,0,10"/>
<TextBlock Grid.Column="3" Grid.Row="2" Text="Last Name" Margin="0,0,0,10"/>
<TextBox x:Name="lastName" Grid.Column="4" Grid.Row="2" Width="150" Margin="0,0,0,10"/>
<TextBlock Grid.Column="1" Grid.Row="3"
Text="Email" Margin="0,0,0,10"/>
<TextBox x:Name="email" Grid.Column="2" Grid.Row="3"
Width="150" Margin="0,0,0,10"/>
<TextBlock Grid.Column="3" Grid.Row="3"
Text="Phone Number" Margin="0,0,0,10"/>
<TextBox x:Name="phonenumber" Grid.Column="4" Grid.Row="3"
Width="150" Margin="0,0,0,10"/>
<TextBlock Grid.Column="1" Grid.Row="4"
Text="Amount" Margin="0,0,0,10"/>
<TextBox x:Name="amount" Grid.Column="2" Grid.Row="4"
Width="150" Margin="0,0,0,10"/>
<Button x:Name="submitButton" Content="Submit"
Grid.Column="4" Grid.Row="4"
Margin="0,0,0,10" Click="SubmitButton_Click" />
<DataGrid x:Name="studentGrid" Grid.Column="1" Grid.Row="5" MinWidth="20" Grid.ColumnSpan="5" Margin="22,0,45,154" Grid.RowSpan="2" ItemsSource="{StaticResource Code360Manager}">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" Binding="{Binding firstName}" />
<DataGridTextColumn Header="Last Name" Binding="{Binding lastName}" />
<DataGridTextColumn Header="Email"
Binding="{Binding email}" />
<DataGridTextColumn Header="Phone Number" Binding="{Binding phonenumber}" />
<DataGridTextColumn Header="Amount" Binding="{Binding amount}" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBlock Text="{Binding Details}" />
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
</Grid>
</Window>