你的位置:首页 > ASP.net教程

[ASP.net教程]课程表WPF制作 学习步骤三


也是由于没用足够时间在查找相关书籍知识上,导致项目进程一直拖延不前,惭愧惭愧;

 

关于之前的展示制作在这里做一个修正:

1.以前的通过进程将两个window联系起来着实麻烦而且是两个项目,无法很好的共用,所以修改为添加新窗口,操作界面如下:


这是一个简单的对话框界面;



 

添加节点到已有

 1 public void addtostring teacher_name, string course_name, string place, string timerow, string timecol) 2     { 3       new  4       "../../Courses.");//找到 5       "Courses"); 6       "course"); 7       xe1.SetAttribute("teacher_name", teacher_name); 8       xe1.SetAttribute("course_name", course_name); 9       xe1.SetAttribute("place", place);10       xe1.SetAttribute("timerow", timerow);11       xe1.SetAttribute("timecol", timecol);12       root.AppendChild(xe1);13       "../../Courses.");14     }

删除

 1 public void DeleteNode() 2     { 3       new  4       "../../Courses."); 5  6       "Courses").ChildNodes; 7  8       foreach (in xnl) 9       {10         if (xn.Name == "course")11         {12           //将xn的属性转换为13           xe.RemoveAttribute("teacher_name");14           xe.RemoveAttribute("course_name");15           xe.RemoveAttribute("place");16           xe.RemoveAttribute("timerow");17           xe.RemoveAttribute("timecol");18         }19       }20       "../../Courses.");21     }

 具体的操作解释见博客:http://www.jb51.net/article/56289.htm

 

在我的save按钮中的点击事件中添加如下代码即可:

 1 private void save_Click(object sender, RoutedEventArgs e) 2     { 3       Create 4       string timerow = "0", timecol = "0"; 5       switch (combobox1.Text) 6       { 7         case "星期一": timecol = "1"; break; 8         case "星期二": timecol = "2"; break; 9         case "星期三": timecol = "3"; break;10         case "星期四": timecol = "4"; break;11         case "星期五": timecol = "5"; break;12         case "星期六": timecol = "6"; break;13         case "星期日": timecol = "7"; break;14         default: MessageBox.Show("非法输入!"); break;15       }16       switch (combobox2.Text)17       {18         case "上午第一节课": timerow = "1"; break;19         case "上午第二节课": timerow = "2"; break;20         case "上午第三节课": timerow = "3"; break;21         case "上午第四节课": timerow = "4"; break;22         case "下午第一节课": timerow = "5"; break;23         case "下午第二节课": timerow = "6"; break;24         case "下午第三节课": timerow = "7"; break;25         case "下午第四节课": timerow = "8"; break;26         case "晚上": timerow = "9"; break;27         default: MessageBox.Show("非法输入!"); break;28       }29       addto30     }

我创建了三个窗口:

一个是MainWindow就是我的母体窗口也就是我在课程表WPF制作 学习步骤二中的窗口;

一个是editwin窗口就是上面的窗口;

一个是Window1窗口,就是中的课程表WPF制作 学习步骤一主界面

 

 

二、XAML与

具体的

 1 <Window x:Class="CuirriculumBegin.window1" 2     "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3     "http://schemas.microsoft.com/winfx/2006/xaml" 4     Title="window1" WindowState="Maximized"> 5   <Window.Resources> 6     <"course-info" Source="Courses." XPath="/Courses/*"></ 7   </Window.Resources> 8   <Grid> 9     <Grid DataContext="{Binding Source={StaticResource course-info}}">10       <Grid.RowDefinitions >11         <RowDefinition Height="90"></RowDefinition>12         <RowDefinition></RowDefinition>13         <RowDefinition></RowDefinition>14         <RowDefinition></RowDefinition>15         <RowDefinition></RowDefinition>16         <RowDefinition></RowDefinition>17         <RowDefinition Height="40"></RowDefinition>18       </Grid.RowDefinitions>19       <Grid.ColumnDefinitions>20         <ColumnDefinition Width="100"></ColumnDefinition>21         <ColumnDefinition></ColumnDefinition>22         <ColumnDefinition></ColumnDefinition>23         <ColumnDefinition></ColumnDefinition>24         <ColumnDefinition></ColumnDefinition>25         <ColumnDefinition></ColumnDefinition>26         <ColumnDefinition></ColumnDefinition>27         <ColumnDefinition></ColumnDefinition>28       </Grid.ColumnDefinitions>29       <TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期一</TextBlock>30       <TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期二</TextBlock>31       <TextBlock Grid.Row="0" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期三</TextBlock>32       <TextBlock Grid.Row="0" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期四</TextBlock>33       <TextBlock Grid.Row="0" Grid.Column="5" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期五</TextBlock>34       <TextBlock Grid.Row="0" Grid.Column="6" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期六</TextBlock>35       <TextBlock Grid.Row="0" Grid.Column="7" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Foreground="#FFBD1096">星期日</TextBlock>36       <TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20">时间段</TextBlock>37       <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Text=" 8:00&#x0a; -- &#x0a; 9:35"></TextBlock>38       <TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Text=" 9:55&#x0a; -- &#x0a;11:30"></TextBlock>39       <TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Text="14:00&#x0a; -- &#x0a;15:35"></TextBlock>40       <TextBlock Grid.Row="4" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Text="15:55&#x0a; -- &#x0a;17:30"></TextBlock>41       <TextBlock Grid.Row="5" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30" Text="晚上"></TextBlock>42       <Image Source="Resources\1.jpeg" Grid.ColumnSpan="8" Grid.RowSpan="7" Opacity="0.4" Stretch="Fill"/>43       <Button x:Name="edit_btn" Grid.Column="2" Grid.Row="6" Margin="0,0,5,10" HorizontalAlignment="Right" Width="110" RenderTransformOrigin="0.511,0.067" Content="Edit" IsCancel="True" BorderBrush="#FF1C84EC" Background="White" Opacity="0.5" Foreground="#FFF50808" OpacityMask="#FFF7F7F7" FontFamily="Simplified Arabic" FontSize="16" Grid.ColumnSpan="2" Click="edit_btn_Click"/>44       <Button x:Name="save_btn" Grid.Column="4" Grid.Row="6" Margin="0,0,79,10" HorizontalAlignment="Right" Width="110" RenderTransformOrigin="0.511,0.067" Content="Save" IsCancel="True" BorderBrush="#FF1C84EC" Background="White" Opacity="0.5" Foreground="#FFF50808" OpacityMask="#FFF7F7F7" FontFamily="Simplified Arabic" FontSize="16" Grid.ColumnSpan="2" Click="save_btn_Click"/>45       <StackPanel Grid.Column="{Binding XPath=@timecol}" Grid.Row="{Binding XPath=@timerow}">46       <TextBlock Text="{Binding XPath=@place}"></TextBlock>47       <TextBlock Text="{Binding XPath=@course_name}"></TextBlock>48       <TextBlock Text="{Binding XPath=@teacher_name}"></TextBlock>49       </StackPanel>50     </Grid>51   </Grid>52 </Window>

 

关于

 

这样大体的成型框架就实现了,操作:

点击Save按钮在Window1中显示如下:

还是要继续学习。。。。。。。

 Over~~