这是WPF的xaml代码:<Window x:Class="BellRingers.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="协会成员" Height="470" Width="600">
<!--<Window.Resources>
<Style x:Key="buttonStyle">
<Setter Property="Button.Background" Value="Gray"/>
<Setter Property="Button.Foreground" Value="white"/>
<Setter Property="Button.FontFamily" Value="comic sans ms"/>
</Style>
</Window.Resources>-->
<Window.Resources>
<Style x:Key="bellRingerFontStyle" TargetType="Control">
<Setter Property="FontFamily" Value="comic sans MS"/>
</Style>
<Style x:Key="bellRingersStyle" TargetType="Control">
<Setter Property="Background" Value="gray"/>
<Setter Property="Foreground" Value="white"/>
<Setter Property="FontFamily" Value="comic sans MS"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="blue"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Image Panel.ZIndex="0" Name="image1">
<Image.Source>
<BitmapImage UriSource="Bell.gif"/>
</Image.Source>
</Image>
<Label Content="First Name:" Height="28" HorizontalAlignment="Left" Margin="39,25,0,0" Name="label1" VerticalAlignment="Top" Width="75" Style="{StaticResource bellRingerFontStyle}" />
<TextBox Style="{DynamicResource bellRingersStyle}" Height="23" HorizontalAlignment="Left" Margin="121,25,0,0" Name="firstName" VerticalAlignment="Top" Width="175" />
<Label Content="Last Name:" Height="28" HorizontalAlignment="Left" Margin="305,25,0,0" Name="label2" VerticalAlignment="Top" Width="75" Style="{StaticResource bellRingerFontStyle}" />
<TextBox Height="23" Style="{DynamicResource bellRingersStyle}" HorizontalAlignment="Left" Margin="380,25,0,0" Name="lastName" VerticalAlignment="Top" Width="175" />
<Label Content="挂钟地点:" Style="{StaticResource bellRingerFontStyle}" Height="28" HorizontalAlignment="Left" Margin="29,72,0,0" Name="label3" VerticalAlignment="Top" Width="75" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="121,72,0,0" Name="towerNames" VerticalAlignment="Top" Width="275" />
<CheckBox Content="Captain" Style="{StaticResource bellRingerFontStyle}" Height="23" HorizontalAlignment="Left" Margin="420,72,0,0" Name="isCaptain" VerticalAlignment="Top" Width="75" />
<Label Content="Member Since:" Style="{StaticResource bellRingerFontStyle}" Height="28" HorizontalAlignment="Left" Margin="29,134,0,0" Name="label4" VerticalAlignment="Top" Width="90" />
<DatePicker Height="23" HorizontalAlignment="Left" Margin="121,134,0,0" Name="memberSince" VerticalAlignment="Top" Width="275" />
<GroupBox Header="资历" Height="200" HorizontalAlignment="Left" Margin="29,174,0,0" Name="yearsExperience" VerticalAlignment="Top" Width="258">
<StackPanel Margin="0,0,0,0" Name="stackPanel1">
<RadioButton Style="{StaticResource bellRingerFontStyle}" Content="Up to 1 year" Height="16" Margin="0,20,0,0" Name="novice" Width="120" />
<RadioButton Style="{StaticResource bellRingerFontStyle}" Content="1 to 4 year" Height="16" Margin="0,20,0,0" Name="intermediate" Width="120"/>
<RadioButton Style="{StaticResource bellRingerFontStyle}" Content="5 to 9 year" Height="16" Margin="0,20,0,0" Name="experienced" Width="120" />
<RadioButton Style="{StaticResource bellRingerFontStyle}" Content="10 to more year" Height="16" Margin="0,20,0,0" Name="accoplished" Width="120" />
</StackPanel>
</GroupBox>
<ListBox Height="200" Style="{StaticResource bellRingerFontStyle}" HorizontalAlignment="Left" Margin="310,174,0,0" Name="methods" VerticalAlignment="Top" Width="245" />
<Button Style="{StaticResource bellRingersStyle}" Content="ADD" Height="23" HorizontalAlignment="Left" Margin="188,388,0,0" Name="add" VerticalAlignment="Top" Width="75" />
<Button Style="{StaticResource bellRingersStyle}" Content="Clear" Height="23" HorizontalAlignment="Left" Margin="313,388,0,0" Name="clear" VerticalAlignment="Top" Width="75" />
</Grid>
</Window>
这是后台的cs代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BellRingers
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private string[] towers = { "天津", "北京", "大上海", "秦皇岛", "牛头崖" };
private string[] ringingMethods = { "大声响", "小声响", "蜂鸣", "狗叫", "鸟叫", "猫叫", "狼叫", "呻吟", "啊噢" };
public MainWindow()
{
InitializeComponent();
this.Reset();
}
public void Reset()
{
firstName.Text = string.Empty;
lastName.Text = string.Empty;
towerNames.Items.Clear();
foreach (string towerName in towers)
{
towerNames.Items.Add(towerNames);
}
towerNames.Text = towerNames.Items[0] as string;
methods.Items.Clear();
CheckBox method = null;
foreach (string methodName in ringingMethods)
{
method = new CheckBox();
method.Margin = new Thickness(0, 0, 0, 10);
method.Content = methodName;
methods.Items.Add(method);
}
isCaptain.IsChecked = false;
novice.IsChecked = true;
memberSince.Text = DateTime.Today.ToString();
}
}
}
这些东西我写了一个上午啊,可运行的时候就是出错啊,看了半天也不知道哪里出错。我用的是VS2010,64位系统,请各位大侠来帮帮忙啊
|