实验课堂练习4
实验效果:
MainWindowd.xaml:
<Window x:Class="实验课堂练习4.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:实验课堂练习4"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.ColumnSpan="2" Fill="white" RadiusX="14" RadiusY="14" Stroke="Blue" StrokeDashArray="3" />
<Rectangle Grid.Column="0" Margin="7" Fill="#FFF0F9D8" RadiusX="10" RadiusY="10" Stroke="Blue" StrokeDashArray="3" />
<Rectangle Grid.Column="0" Margin="20" Fill="White" Stroke="Blue" />
<ScrollViewer Grid.Column="0" Margin="22">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="5 10 5 0" />
<Setter Property="Padding" Value="10 0 10 0"/>
<EventSetter Event="Click" Handler="button_Click" />
</Style>
</StackPanel.Resources>
<Button Content="例1" Tag="Examples/LambdaExample.xaml" />
<Button Content="例2" Tag="Examples/ActionAndFunc.xaml" />
<Button Content="例3" Tag="Examples/TaskRunExamplePage.xaml" />
<Button Content="例4" Tag="Examples/async_awaitExamplePage.xaml" />
<Button Content="例5" Tag="Examples/InvokeAsyncExamplePage.xaml" />
<Button Content="例6" Tag="Examples/CancellationTokenPage.xaml" />
<Button Content="例7" Tag="Examples/TaskStatusExamplePage.xaml" />
<Button Content="例8" Tag="Examples/IProgressExamplePage.xaml" />
<Button Content="例9" Tag="Examples/TimersPage.xaml" />
</StackPanel>
</ScrollViewer>
<Frame Name="frame1" Grid.Column="1" Margin="10" BorderThickness="1" BorderBrush="Blue" NavigationUIVisibility="Hidden" />
</Grid>
</Window>
MainWindowd.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 实验课堂练习4
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private Button oldButton = new Button();
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender,RoutedEventArgs e)
{
Button btn = e.Source as Button;
oldButton.Foreground = Brushes.Black;
btn.Foreground = Brushes.Red;
oldButton = btn;
frame1.Source = new Uri(btn.Tag.ToString(), UriKind.Relative);
}
}
}
App.xaml:
<Application x:Class="实验课堂练习4.App"
xmlns="http://schemas.m