我有一个 C# 项目:
XAML 代码:
<Window x:Class="Revision.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Patient Information" Height="456.36" Width="935.208">
<Window.Resources>
<Style x:Key="SliderStyle">
<Setter Property="FrameworkElement.Width" Value="100"/>
<Setter Property="RangeBase.Minimum" Value="0"/>
<Setter Property="RangeBase.Maximum" Value="100"/>
<Setter Property="Slider.IsSnapToTickEnabled" Value="true"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="RangeBase.Value" Value="0"/>
<Setter Property="Slider.AutoToolTipPlacement" Value="TopLeft"/>
</Style>
</Window.Resources>
<Grid>
<Label Content="First Name" Height="28" HorizontalAlignment="Left" Margin="19,23,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="Last Name" Height="28" HorizontalAlignment="Left" Margin="19,82,0,0" Name="label2" VerticalAlignment="Top" />
<Label Content="Address" Height="28" HorizontalAlignment="Left" Margin="20,144,0,0" Name="label3" VerticalAlignment="Top" />
<Label Content="Security Type" Height="28" HorizontalAlignment="Left" Margin="19,203,0,0" Name="label4" VerticalAlignment="Top" />
<TextBox Height="36" HorizontalAlignment="Left" Margin="105,23,0,0" Name="textBox1" VerticalAlignment="Top" Width="197" />
<TextBox Height="36" HorizontalAlignment="Left" Margin="105,82,0,0" Name="textBox2" VerticalAlignment="Top" Width="197" />
<TextBox Height="36" HorizontalAlignment="Left" Margin="105,136,0,0" Name="textBox3" VerticalAlignment="Top" Width="197" />
<ComboBox Height="36" Margin="105,195,625,0" Name="comboBox1" VerticalAlignment="Top">
<ComboBoxItem Content="Private Assurance" Name="PrA"/>
<ComboBoxItem Content="Public Assurance" Name="PA"/>
<ComboBoxItem Content="No Assurance" Name="NA"/>
</ComboBox>
<Button Content="Submit" Height="33" HorizontalAlignment="Left" Margin="147,365,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
<Button Content="Display" Height="33" HorizontalAlignment="Left" Margin="227,365,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
<Label Content="Gender" HorizontalAlignment="Left" Margin="20,255,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="maleRadio" Content="Male" HorizontalAlignment="Left" Margin="105,266,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="femaleRadio" Content="Female" HorizontalAlignment="Left" Margin="192,266,0,0" VerticalAlignment="Top"/>
<Slider x:Name="redSlider" Style="{StaticResource SliderStyle}" Value="{Binding Text, ElementName=textBox5}" Margin="74,313,636,56" SmallChange="1" Height="56" Width="Auto" />
<TextBox x:Name="textBox5" Text="{Binding Value, ElementName=redSlider}" Margin="296,313,588,86" SelectionOpacity="1" FontSize="13" />
<Label Content="Age" HorizontalAlignment="Left" Margin="38,313,0,0" VerticalAlignment="Top"/>
<ListView x:Name="ListView1" HorizontalAlignment="Left" Height="375" Margin="344,23,0,0" VerticalAlignment="Top" Width="567">
<ListView.View>
<GridView>
<GridViewColumn Header="First Name" Width="100"
DisplayMemberBinding="" />
<GridViewColumn Header="Last Name" Width="80"
DisplayMemberBinding="" />
<GridViewColumn Header="Address" Width="100"
DisplayMemberBinding="" />
<GridViewColumn Header="Security Type" Width="80"
DisplayMemberBinding="" />
<GridViewColumn Header="Gender" Width="100"
DisplayMemberBinding="" />
<GridViewColumn Header="Age" Width="100"
DisplayMemberBinding="" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
我有一个班级病人:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Revision
{
class Patient
{
public string firstname { get; set; }
public string lastname { get; set; }
public string Address { get; set; }
public string securityType {get; set;}
public string gender { get; set; }
public string age { get; set; }
public Patient(string fn, string ln, string ad, string st,string ge,string ag)
{
firstname = fn;
lastname = ln;
Address = ad;
securityType = st;
gender = ge;
age = ag;
}
public override string ToString()
{
return string.Format("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10} {5,-10}",
firstname, lastname, Address, securityType, gender,age);
}
}
}
和主程序
public partial class MainWindow : Window
{
// Patient [] patients = new Patient{}
Patient [] patients = new Patient[100];
private List<Patient> books = new List<Patient>();
int i=0;
string g;
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string x = "";
if (PrA.IsSelected)
{
x = PrA.Content.ToString();
}
else if (PA.IsSelected)
{
x = PA.Content.ToString();
}
else if (NA.IsSelected)
{
x = NA.Content.ToString();
}
if (maleRadio.IsChecked == true)
g = "Male";
if(femaleRadio.IsChecked==true)
g="Female";
patients[i] = new Patient(
textBox1.Text, textBox2.Text, textBox3.Text, g, textBox5.Text, x);
i = i + 1;
// Patient[] patients = {
// new Patient (
// textBox1.Text, textBox2.Text, textBox3.Text, x)};
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox5.Clear();
}
}
所以我想在列表视图中显示在文本框、单选按钮和组合框中输入的数据的问题...